4

on click event doesn't respond to right mouse click. The event is for a richTextBox. when I try the same code on the form it works fine.

what could be the problem?

EDIT: I use winforms

Drake
  • 8,225
  • 15
  • 71
  • 104
Alex K
  • 5,092
  • 15
  • 50
  • 77
  • 2
    Do you mean RichTextBox and also is this WPF or ASP.NET or Winforms – Leom Burke Jun 24 '10 at 09:12
  • Please show your code. edit: If you are using javascript (for instance) it's a complete different problem then if you are using winform. – MrFox Jun 24 '10 at 09:12
  • I use winforms. Their is no point in my code cause it's simple code that includes the event function and messagebox that should popup on the right click event. – Alex K Jun 24 '10 at 09:45
  • Even though your problem is resolved, it would be nice if you could post a small code sample for the benefit of the community - so when someone else has the same problem there is already an available solution. – Chris Shouts Jun 24 '10 at 12:49

2 Answers2

10

You need to check it on the MouseDown event.

private void TextBox_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
        wasRightButtonClicked = true;
}
John Kraft
  • 6,811
  • 4
  • 37
  • 53
shookdiesel
  • 277
  • 1
  • 10
5

The Click and MouseClick events are only generated by a left-click. If you want to detect right-clicks then you have to implement the MouseDown or MouseUp event.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536