Capture simultaneous right and left click event triggers on label
Asked Answered
B

1

1

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");
    }
}
Buckish answered 13/12, 2011 at 7:38 Comment(3)
perhaps logic can be combined with pressed event.Weft
AFAIK, you have to check it explicitly. Check out this question: #1183393Antinucleon
take a look at here java2s.com/Code/CSharp/Event/…Rancher
S
2

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

Soninlaw answered 13/12, 2011 at 7:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.