Visual C# Form right click button

后端 未结 3 1542
北海茫月
北海茫月 2020-12-20 12:46

I am trying to make a minesweeper type game in visual c# and I want to have different things happen when I right click and left click a button, how do I do this?

I h

3条回答
  •  一整个雨季
    2020-12-20 13:33

    Button is reacting only for MouseButtons.Left not for MouseButton.Right and not even for middle.

    void Select(object sender, MouseEventArgs e)
    {
        /* var btn = sender as CardButton;*/
    
        if (e.Button == MouseButtons.Left)
        {
            if (this.Selected == false)
            { 
                this.Selected = true;
            }
            else
            {
                this.Selected = false;
            }
        }
        if (e.Button == MouseButtons.Right)
        {
            if (this.Selected == false)
            {
                this.Selected = true;
            }
            else
            {
                this.Selected = false;
            }
        }
    
        Draw();
    }
    

提交回复
热议问题