MouseClick Issue
-
:confused:Howdy, Hope somebody can help me. I have a C# Windows Application (.Net 2) and on it is a label. I add an event handler for the label_MouseClick event. The event handler is called when I click the label so it all works as advertised. My question is, how on earth do I capture that the left and right buttons were clicked together? I can check the MouseEventArgs object to get the button used, but don't have and option for both buttons. Is there any easy way to capture the two buttons' click or must I write a whole bunch of code to check for both buttons? Any help would be appreciated. I used to be vain.... BUT now I'm perfect!
You can get the Mousebuttons in the MouseDown event, use the MouseEventArgs object and check the button property e.g. if(e.Button == System.Windows.Forms.MouseButtons.Left) { //Todo } else if(e.Button == System.Windows.Forms.MouseButtons.Right) { //Todo } Hope that works for u fine. Regards, Pramod
-
You can get the Mousebuttons in the MouseDown event, use the MouseEventArgs object and check the button property e.g. if(e.Button == System.Windows.Forms.MouseButtons.Left) { //Todo } else if(e.Button == System.Windows.Forms.MouseButtons.Right) { //Todo } Hope that works for u fine. Regards, Pramod
That part I do understand and it is rather easy. To quote my original question: "My question is, how on earth do I capture that the left and right buttons were clicked together?" I used to be vain.... BUT now I'm perfect!
-
That part I do understand and it is rather easy. To quote my original question: "My question is, how on earth do I capture that the left and right buttons were clicked together?" I used to be vain.... BUT now I'm perfect!
It can never ever on Earth happen that Left and Right buttons are clicked together, the user clicks it together but only one click is trapped first by the O.S. The O.S gets the click of either button and then the other so u can check both of them by writing Two if conditions. Wht do u want to do by checking both buttons? Regards, Pramod
-
It can never ever on Earth happen that Left and Right buttons are clicked together, the user clicks it together but only one click is trapped first by the O.S. The O.S gets the click of either button and then the other so u can check both of them by writing Two if conditions. Wht do u want to do by checking both buttons? Regards, Pramod
"Wht do u want to do by checking both buttons?" Same as on the MineSweeper game, when I click both buttons I want to mark something. I used to be vain.... BUT now I'm perfect!
-
It can never ever on Earth happen that Left and Right buttons are clicked together, the user clicks it together but only one click is trapped first by the O.S. The O.S gets the click of either button and then the other so u can check both of them by writing Two if conditions. Wht do u want to do by checking both buttons? Regards, Pramod
Here is a solution that works OK (not great but it works):
private bool rightButton; private bool leftButton; private void newLabel_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { leftButton = true; } if (e.Button == MouseButtons.Right) { rightButton = true; } } private void newLabel_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { // Do something on right click; } else if (e.Button == MouseButtons.Middle || (leftButton && rightButton)) { // Do something on middle click OR left and right click together; } else { // Do something on left click; } } private void newLabel_MouseUp(object sender, MouseEventArgs e) { rightButton = false; leftButton = false; }
I used to be vain.... BUT now I'm perfect! -- modified at 6:31 Monday 20th March, 2006 -
Here is a solution that works OK (not great but it works):
private bool rightButton; private bool leftButton; private void newLabel_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { leftButton = true; } if (e.Button == MouseButtons.Right) { rightButton = true; } } private void newLabel_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { // Do something on right click; } else if (e.Button == MouseButtons.Middle || (leftButton && rightButton)) { // Do something on middle click OR left and right click together; } else { // Do something on left click; } } private void newLabel_MouseUp(object sender, MouseEventArgs e) { rightButton = false; leftButton = false; }
I used to be vain.... BUT now I'm perfect! -- modified at 6:31 Monday 20th March, 2006 -
Well, no more problem, this is my solution to the problem. Thought I would give feedback. I used to be vain.... BUT now I'm perfect!
-
Well, no more problem, this is my solution to the problem. Thought I would give feedback. I used to be vain.... BUT now I'm perfect!
-
Thanks a lot, well are u creating any game in c#? If u could tell me in detail, it would be gr8!! Thanks, Pramod
I just re-wrote Microsoft's MineSweeper to see if I could do it. It took me 8 hours and 747 lines of code (excluding saving of high scores and sound effects) and the last thing I had to sort out was the clicking of both buttons to expose the buttons that doesn't have mines under it. Nothing spectacular, just a little exercise over the weekend. I used to be vain.... BUT now I'm perfect!
-
:confused:Howdy, Hope somebody can help me. I have a C# Windows Application (.Net 2) and on it is a label. I add an event handler for the label_MouseClick event. The event handler is called when I click the label so it all works as advertised. My question is, how on earth do I capture that the left and right buttons were clicked together? I can check the MouseEventArgs object to get the button used, but don't have and option for both buttons. Is there any easy way to capture the two buttons' click or must I write a whole bunch of code to check for both buttons? Any help would be appreciated. I used to be vain.... BUT now I'm perfect!
private void mylabel_MouseClick(object sender, EventsArgs e)
{
if(e.MouseButton == MouseButtons.Left)
MessageBox.Show("You've just pressed the Left mouse button!");
else if(e.MouseButton == MouseButtons.Middle)
MessageBox.Show("You clicked the middle mouse button");
else if(e.MouseButton == MouseButtons.Right)
MessageBox.Show("You clicked the right mouse buttom");
}