问题
I'm trying to add a double click event to a button in winforms but it never executes in run-time. My buttons are created dynamically at run-time
This is what I am trying at the moment:
buttons[r][c].MouseDoubleClick += new MouseEventHandler(mouseDBL_Click);
private void mouseDBL_Click(object sender, EventArgs e)
{
// do something
}
I also tried:
buttons[r][c].DoubleClick += new EventHandler(gridDBL_Click);
private void gridDBL_Click(object sender, EventArgs e)
{
// do something
}
I really don't understand why this does not work.
回答1:
Use the MouseClick
event and check the Clicks
property
private void button1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Clicks >= 2)
{
}
}
UPDATE
Apologies, I just tried it and it seems to not work. I looked up more about why this is. You can find the answer here:
WinForms how to call a Double-Click Event on a Button?
Very odd that it is included if it does not work. In fact, that event doesn't even seem to fire.
来源:https://stackoverflow.com/questions/15422675/button-double-click-event