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,081
  • 3
  • 18
  • 38
Tacit
  • 870
  • 5
  • 16
  • 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,569
  • 10
  • 59
  • 108