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 have tried this code but it only registers left clicks:
private void button1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
MessageBox.Show("Left");
}
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
MessageBox.Show("Right");
}
}
Just try with
button1_MouseDown
event instead ofbutton1_MouseClick
Event.It will solve your problem.You will have to use the
MouseUp
orMouseDown
event instead of theClick
event to capture right click.Button is reacting only for
MouseButtons.Left
not forMouseButton.Right
and not even for middle.