I have a button that I trigger OnClick
whenever there is a click on that button. I would like to know which Mouse button clicked on that button?
When I use the Mouse.LeftButton
or Mouse.RightButton
, both tell me "realsed" which is their states after the click.
I just want to know which one clicked on my button. If I change EventArgs
to MouseEventArgs
, I receive errors.
XAML: <Button Name="myButton" Click="OnClick">
private void OnClick(object sender, EventArgs e)
{
//do certain thing.
}
You can cast like below:
MouseEventArgs myArgs = (MouseEventArgs) e;
And then get the information with:
if (myArgs.Button == System.Windows.Forms.MouseButtons.Left)
{
// do sth
}
The solution works in VS2013 and you do not have to use MouseClick event anymore ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With