0

I had try to press button with right click, but the button doesn't seen to be pressed like left click.

And so I can't raise the MouseClick event with right click.

private void ButRightClick(object sender, MouseEventArgs e)
{
        if (e.Button == MouseButtons.Right)
            MessageBox.Show("Right");
        else
            MessageBox.Show("Left");
}

But if I change the event to labels, it will work on both right and left click.

private void label2_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
                MessageBox.Show("Right");
            else
                MessageBox.Show("Left");
        }

Is there property I need to modify for the buttons?

Or maybe the function is remove, since Microsoft has the Doc(https://learn.microsoft.com/en-us/dotnet/framework/winforms/mouse-events-in-windows-forms)

The following controls do not conform to the standard mouse click event behavior:

Button, CheckBox, ComboBox, and RadioButton controls:

Left click: Click, MouseClick

Right click: No click events raised

Left double-click: Click, MouseClick; Click, MouseClick

Right double-click: No click events raised

Is there no way to use right click on buttons?

Thanks for any help.

Ben Huang
  • 7
  • 1
  • Possible duplicate of [Visual C# Form right click button](https://stackoverflow.com/questions/9450382/visual-c-sharp-form-right-click-button) – Broots Waymb Nov 29 '18 at 16:20
  • 3
    OnClick does not handle right click events for Buttons. The solution is to use MouseUp/MouseDown – Sebastian Siemens Nov 29 '18 at 16:24
  • 1
    It would be good if you showed your event subscription code (roughly `button.SomeEvent += MyEventHandler`). Are you handling `Click` or `MouseClick`. Click on a button is raised when someone left-mouse-downs on the button and then releases the mouse button while still over the button. – Flydog57 Nov 29 '18 at 16:25
  • I had find the solution, my button had two event subscription code ButReset.Click += new EventHandler(this.ButReset_Click); ButReset.MouseClick+=newMouseEventHandler(this.ButReset_MouseClick) Since I remove the .Click event the right click start to work, but left click is just work fine when both event is subscrip, can anyone help me explan that? tkx – Ben Huang Nov 29 '18 at 16:38

0 Answers0