Вопрос

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");
    }
}
Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top