Button double click event [duplicate]

懵懂的女人 提交于 2020-08-05 09:31:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!