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. Handle mouse move events in C#

Handle mouse move events in C#

Scheduled Pinned Locked Moved C#
csharphelpworkspace
4 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.
  • S Offline
    S Offline
    sumeat
    wrote on last edited by
    #1

    Hi, I have a MDI application, which has a workspace (a form) and a tool bar window. User can create new forms and place controls from the tool bar onto this forms. They should be able to move controls on this form. Here is the problem: To let user move controls around on the form, I handle the MouseDown, MouseMove and MouseUp events for the selected control. In the MouseMove event handler I compute (using the location value saved in Mouse Down event) the new location for the control and set it as the location of the control. This somehow cause more mouse move events on the control - this is because, I think, the assignment of new value to the location property cause the control to move to the new location while it has the mouse pointer on it. This may generate new mouse move events!!! Any suggestions / solutions to avoid the extra mouse move events would be highly appreciated. Thanks, Suhas

    N 1 Reply Last reply
    0
    • S sumeat

      Hi, I have a MDI application, which has a workspace (a form) and a tool bar window. User can create new forms and place controls from the tool bar onto this forms. They should be able to move controls on this form. Here is the problem: To let user move controls around on the form, I handle the MouseDown, MouseMove and MouseUp events for the selected control. In the MouseMove event handler I compute (using the location value saved in Mouse Down event) the new location for the control and set it as the location of the control. This somehow cause more mouse move events on the control - this is because, I think, the assignment of new value to the location property cause the control to move to the new location while it has the mouse pointer on it. This may generate new mouse move events!!! Any suggestions / solutions to avoid the extra mouse move events would be highly appreciated. Thanks, Suhas

      N Offline
      N Offline
      Nnamdi Onyeyiri
      wrote on last edited by
      #2

      as long as the mouse moves, there will be mousemove events, try keeping track of when a control is being moved, using a boolean variable, and if its not being moved, then dont run all hte code in your MouseMove. Another Post by NnamdiOnyeyiri l Website

      S 1 Reply Last reply
      0
      • N Nnamdi Onyeyiri

        as long as the mouse moves, there will be mousemove events, try keeping track of when a control is being moved, using a boolean variable, and if its not being moved, then dont run all hte code in your MouseMove. Another Post by NnamdiOnyeyiri l Website

        S Offline
        S Offline
        sumeat
        wrote on last edited by
        #3

        I am sorry I do not understand your suggestion. The control does not move on its own, it moves in response to mouse move events. Even when the mouse has stopped moving the control continues to receive mouse move events because the control itself is moving in response to the previous mouse move events. I suspect that this extra mouse move events are generated because the control the has mouse pointer on it when it is moving. The pseudo code is: MyMouseMoveHandler() { // Compute the move distance // Move the control - this itself it generating more mouse move events // even though the mouse has stopped moving. } Thanks, Suhas

        I 1 Reply Last reply
        0
        • S sumeat

          I am sorry I do not understand your suggestion. The control does not move on its own, it moves in response to mouse move events. Even when the mouse has stopped moving the control continues to receive mouse move events because the control itself is moving in response to the previous mouse move events. I suspect that this extra mouse move events are generated because the control the has mouse pointer on it when it is moving. The pseudo code is: MyMouseMoveHandler() { // Compute the move distance // Move the control - this itself it generating more mouse move events // even though the mouse has stopped moving. } Thanks, Suhas

          I Offline
          I Offline
          Ista
          wrote on last edited by
          #4

          try setting handled to true and that might stop the flow of events I'm not an expert yet, but I play one at work. Yeah and here too.

          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