Mouse move events

S

suhas

Hi,

I have an MDI app that allows user to create flowcharts.
User can drag flowchart objects (squares, rectangles,
elipses, etc) from the toolbar and put on a form. They
should be able to move the objects around on the form.

This is where the problem is, I have implemented this
using the mouse_down, mouse_up and mouse_move events of
the form. When user selects a object, I receive the
mouse_down mesg, in which I save the current mouse
coordinates. When user drags the object around I receive
mouse move events, in which I compute the distance that
the mouse has moved and move the object by that distance.
When the object is moved, that itself generates new
mouse_move events in the opposite direction. Why are these
events generated and how can I prevent them?

Thanks,
Suhas
 
J

Jeremy Wilde

I dealt with this myself. I made a form that would move with the mouse, below is the code from the Mouse Move event handler I am
using. It doesn't stop the additional event that occurs when you reposition the object. When I update my lastPos I set it to where
the next move event would put it so that it works out that no move at all occurs and prevents the event from firing a third time
from a single user action.



if (mouseDown)

{

int XOff = e.X - lastPos.X;

int YOff = e.Y - lastPos.Y;

Console.WriteLine("Xoff:{0} Yoff:{1}", XOff, YOff);

this.Left += XOff;

this.Top += YOff;

lastPos = new Point(e.X - XOff, e.Y - YOff);

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top