Capture simultaneous right and left click event triggers on label

空扰寡人 提交于 2019-12-11 10:27:12

问题


I'm writing a simple minesweeper game over my Christmas break and I'm adding in the feature where you click with both mouse buttons on a number and it unveils the hidden boxes around it when it's safe to do so. ie the number is a 1 and you've flagged 1 mine, so it uncovers all other boxes next to the 1. Quick side note: I love that minesweeper is a tag.

I have a mouse click event on the label, but there is no "Both right and left buttons together" option for System.Windows.Forms.MouseButtons. So, how do I do this?

private void label1_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left && 
        e.Button == System.Windows.Forms.MouseButtons.Right)
    {
        MessageBox.Show("doesn't work");
    }
}

回答1:


You can't do that - it's either Left or Right or None, not BOTH.

BUT, you can simulate it.

you can save which button was clicked, along with the current time, then, on the next click, if the pressed button is DIFFERENT than the first click, and the time difference is, lets say, <10ms, then count it as BOTH buttons clicked



来源:https://stackoverflow.com/questions/8485779/capture-simultaneous-right-and-left-click-event-triggers-on-label

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