Reputation: 5386
I am trying to create a simple windows form applicaiton in c# which will count the right left clicks from the mouse event. I have copy the following code which detect the click event:
private void mouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Trace.WriteLine("Mouse clicked");
}
}
And in Form method I add this.MouseClick += mouseClick;
. My issue is that this function activates every time a click is performed whether is right or left click. Why is that?
Upvotes: 1
Views: 4285
Reputation: 26886
It is by design. MouseClick
event is raised on every click - doesn't matter was it caused by left or right button.
In order to distinguish left button from right one in this event handler - you have to check e.Button
property exactly as it was done in your code:
if (e.Button == MouseButtons.Right)
Upvotes: 5