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. Do something while the mouse button is down

Do something while the mouse button is down

Scheduled Pinned Locked Moved C#
10 Posts 6 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.
  • D Offline
    D Offline
    Dana Tov
    wrote on last edited by
    #1

    Hi, In windows application - I want the user to press a button and while the button is pressed I will do something... I tryed the mouse down event but it only doing it once and I want to do the same function as long as the button is pressed (or the mouse button is down) Thanks

    dana Tov

    C D L S H 5 Replies Last reply
    0
    • D Dana Tov

      Hi, In windows application - I want the user to press a button and while the button is pressed I will do something... I tryed the mouse down event but it only doing it once and I want to do the same function as long as the button is pressed (or the mouse button is down) Thanks

      dana Tov

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      On the mouse down event start a new thread that does the work. On the mouse up event signal the other thread to stop working.


      Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." Ready to Give up - Your help will be much appreciated. My website

      1 Reply Last reply
      0
      • D Dana Tov

        Hi, In windows application - I want the user to press a button and while the button is pressed I will do something... I tryed the mouse down event but it only doing it once and I want to do the same function as long as the button is pressed (or the mouse button is down) Thanks

        dana Tov

        D Offline
        D Offline
        Dana Tov
        wrote on last edited by
        #3

        Thanks!! Is there a way to do it in a single thread?

        dana Tov

        1 Reply Last reply
        0
        • D Dana Tov

          Hi, In windows application - I want the user to press a button and while the button is pressed I will do something... I tryed the mouse down event but it only doing it once and I want to do the same function as long as the button is pressed (or the mouse button is down) Thanks

          dana Tov

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, a keyboard key has autorepeat, so it will generate multiple KeyDown and KeyPressed events when you hold the key down. A mouse button does not. If you need a repeat for the mouse button (or a faster repeat for a keyboard key) you can use a Forms.Timer that runs all the time, and checks whether the ccndition is satisfied (either key is down or mouse button is down). For "key is down", set a variable lastKey to the key that is down in KeyDown, and set it to Keys.None in KeyUp; for "mouse is down" use Control.MouseButtons (there also is Control.ModifierKeys for CTRL/ALT/SHIFT). :)

          Luc Pattyn


          try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


          1 Reply Last reply
          0
          • D Dana Tov

            Hi, In windows application - I want the user to press a button and while the button is pressed I will do something... I tryed the mouse down event but it only doing it once and I want to do the same function as long as the button is pressed (or the mouse button is down) Thanks

            dana Tov

            S Offline
            S Offline
            sam
            wrote on last edited by
            #5

            Mouse down is a single thread event -TRUE But you can use multi threading in it. start a thread on mouse down and stop it on mouse up

            M 1 Reply Last reply
            0
            • S sam

              Mouse down is a single thread event -TRUE But you can use multi threading in it. start a thread on mouse down and stop it on mouse up

              M Offline
              M Offline
              Martin 0
              wrote on last edited by
              #6

              sam# wrote:

              start a thread on mouse down and stop it on mouse up

              Dejavue![^]

              S 1 Reply Last reply
              0
              • M Martin 0

                sam# wrote:

                start a thread on mouse down and stop it on mouse up

                Dejavue![^]

                S Offline
                S Offline
                sam
                wrote on last edited by
                #7

                i am sorry!! i didn't see that Mr. Martin. but it seems you are quite good in peeping other's reply

                M 1 Reply Last reply
                0
                • S sam

                  i am sorry!! i didn't see that Mr. Martin. but it seems you are quite good in peeping other's reply

                  M Offline
                  M Offline
                  Martin 0
                  wrote on last edited by
                  #8

                  sam# wrote:

                  i didn't see that

                  I assumed that. I forgot to mark it as "Joke"

                  sam# wrote:

                  Mr. Martin

                  Come on! :(

                  sam# wrote:

                  but it seems you are quite good in peeping other's reply

                  Really???

                  L 1 Reply Last reply
                  0
                  • M Martin 0

                    sam# wrote:

                    i didn't see that

                    I assumed that. I forgot to mark it as "Joke"

                    sam# wrote:

                    Mr. Martin

                    Come on! :(

                    sam# wrote:

                    but it seems you are quite good in peeping other's reply

                    Really???

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    :-D

                    Luc Pattyn


                    try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


                    1 Reply Last reply
                    0
                    • D Dana Tov

                      Hi, In windows application - I want the user to press a button and while the button is pressed I will do something... I tryed the mouse down event but it only doing it once and I want to do the same function as long as the button is pressed (or the mouse button is down) Thanks

                      dana Tov

                      H Offline
                      H Offline
                      Hesham Yassin
                      wrote on last edited by
                      #10

                      you can do it using two events: 1. when mouse down 2. when mouse get off the button range in step #1, you know that the mouse is down. in step #2 you know that the mouse left the button, then you can stop the thread you started in the first event!:):):):)

                      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