"Jon Cosby" <jc****@nospam.net> wrote in
news:7k*****************@newsread2.news.pas.earthl ink.net:
I need an event handler for dragging the cursor on a PictureBox. The
existing events only include handlers for dragging and dropping objects
over the controls. I'm trying to use the MouseDown and MouseUp handlers
as below, but it never gets out of the while loop.
this.PicBox.MouseDown += new MouseEventHandler(this.StartMapDrag);
this.PicBox.MouseUp += new MouseEventHandler(this.EndMapDrag);
private void StartMapDrag(object sender, MouseEventArgs e)
{
drag = true;
WhileDrag();
}
private void EndMapDrag(object sender, MouseEventArgs e)
{
drag = false;
}
private void WhileDrag()
{
while (drag)
{
// Do something here
}
}
Can someone tell me a better way to handle this event?
The gui is single threaded. This means that the gui's process is
executing the WhileDrag while loop and is never doing something else. You
could opt for an Application.DoEvents() in teh while(drag) loop, as that
would handle all messages currently stored at the message pump and for
example would hten call a mouse handler routine.
Drag and drop however is not something you should babysit. Drag &
Drop starts when a user selects something and moves the mouse while
keeping the lmb down. All you then have to monitor is when teh mouse
button is released. If that's the case inside your window (f.e. in a
picture box) you have to check if a drag & drop action is going on. If so,
do a copy action for example, of the selected item(s) which were selected
when the drag started.
FB
--
Get LLBLGen Pro, the new O/R mapper for .NET:
http://www.llblgen.com
My .NET Blog:
http://weblogs.asp.net/fbouma
Microsoft C# MVP