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