This seems like it it should work but its not. I put a debug stop on the SWITCH statement. This event is only getting triggered on left click. Nothing happens and method is not fired on middle or right click. Any ideas? P.S. I already tried using MouseUp and MouseDown events and same issue.
Here is my code:
this.textBox1.MouseClick +=
new System.Windows.Forms.MouseEventHandler(this.textBox1_MouseClick);
private void textBox1_MouseClick(object sender, MouseEventArgs e)
{
switch (e.Button)
{
case MouseButtons.Left:
// Left click
textBox1.Text = "left";
break;
case MouseButtons.Right:
// Right click
textBox1.Text = "right";
break;
case MouseButtons.Middle:
// Middle click
textBox1.Text = "middle";
break;
}
}
textBox1_MouseDown
event instead ! This works fine here; to avoid the context menue popping up you may want to disable ShortCuts. Btw: It is recommended to test a mousebutton like this:if (e.Button.HasFlag(MouseButtons.Left)).. etc
.. – Durgyswitch
statement? – Durgythis.textBox1.MouseDown += ...
– Lifeanddeath