Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#, mouseClickEvent doesn't respond to right mouse click

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

like image 901
Alex Kapustian Avatar asked Dec 12 '22 21:12

Alex Kapustian


2 Answers

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;
}
like image 74
shookdiesel Avatar answered Dec 28 '22 16:12

shookdiesel


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.

like image 40
Hans Passant Avatar answered Dec 28 '22 17:12

Hans Passant