2

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.

AustinWBryan
  • 3,249
  • 3
  • 24
  • 42
Tacit
  • 890
  • 6
  • 17
  • 42

1 Answers1

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.

Community
  • 1
  • 1
Matt
  • 6,787
  • 11
  • 65
  • 112
  • I didn't even know that property was there! Awesome! – Eric Falsken Mar 15 '13 at 02:11
  • yes it works, thank you very much. My code is like: (Use the link above) DoubleClickButton button = new DoubleClickButton(); button.DoubleClick += delegate (object sender, EventArgs e) { //codes }; – Yağmur Kopar Dec 23 '20 at 11:26