Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. MouseClick Issue

MouseClick Issue

Scheduled Pinned Locked Moved C#
csharphelpquestion
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Pietman Kahl

    :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!

    A Offline
    A Offline
    AB7771
    wrote on last edited by
    #2

    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

    P 1 Reply Last reply
    0
    • A AB7771

      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

      P Offline
      P Offline
      Pietman Kahl
      wrote on last edited by
      #3

      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!

      A 1 Reply Last reply
      0
      • P Pietman Kahl

        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!

        A Offline
        A Offline
        AB7771
        wrote on last edited by
        #4

        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

        P 2 Replies Last reply
        0
        • A AB7771

          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

          P Offline
          P Offline
          Pietman Kahl
          wrote on last edited by
          #5

          "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!

          1 Reply Last reply
          0
          • A AB7771

            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

            P Offline
            P Offline
            Pietman Kahl
            wrote on last edited by
            #6

            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

            A 1 Reply Last reply
            0
            • P Pietman Kahl

              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

              A Offline
              A Offline
              AB7771
              wrote on last edited by
              #7

              So wht's the prob?

              P 1 Reply Last reply
              0
              • A AB7771

                So wht's the prob?

                P Offline
                P Offline
                Pietman Kahl
                wrote on last edited by
                #8

                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!

                A 1 Reply Last reply
                0
                • P Pietman Kahl

                  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!

                  A Offline
                  A Offline
                  AB7771
                  wrote on last edited by
                  #9

                  Thanks a lot, well are u creating any game in c#? If u could tell me in detail, it would be gr8!! Thanks, Pramod

                  P 1 Reply Last reply
                  0
                  • A AB7771

                    Thanks a lot, well are u creating any game in c#? If u could tell me in detail, it would be gr8!! Thanks, Pramod

                    P Offline
                    P Offline
                    Pietman Kahl
                    wrote on last edited by
                    #10

                    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!

                    1 Reply Last reply
                    0
                    • P Pietman Kahl

                      :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!

                      B Offline
                      B Offline
                      Baeltazor
                      wrote on last edited by
                      #11

                      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");
                      }

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups