problem with drag and drop

S

Sam Martin

hi all

i have a user control which consumes the doubleclick event.
when i use this control and implement drag and drop functionality, i.e. on
mousedown check that the left button has been pressed, the DoDragDrop(...
Problem is, because DoDragDrop is always called when the left Mouse button
is pressed, the double click in the user control isn't being fired?

any ideas?

TIA
Sam Martin
 
J

John Wood

The DoDragDrop is likely capturing the mouse, so the control never gets the
second mouse click.
One solution is to use a timer. On the left mouse down you enable the timer
(which can go off after a duration no less than
SystemInformation.DoubleClickTime), when the double click event is raised
you disable the timer and perform your double click processing. When the
timer goes off, you know you should begin dragging.

Hope that helps.
John
 
S

Sam Martin

about to find out if that works mate
thanks

John Wood said:
The DoDragDrop is likely capturing the mouse, so the control never gets the
second mouse click.
One solution is to use a timer. On the left mouse down you enable the timer
(which can go off after a duration no less than
SystemInformation.DoubleClickTime), when the double click event is raised
you disable the timer and perform your double click processing. When the
timer goes off, you know you should begin dragging.

Hope that helps.
John
 
S

Sam Martin

ok, the timer idea didn't work, as the DoDragDrop returned immediately,
would appear that it has to be called on a mouse
event...understandably...but thanks for the help...it gave me another idea
by using the mouse position

if anyone has the same problem....

i simply, create a member var (boolean) to hold whether or not the mouse
button was down.

i.e. on mouse down, check to make sure the left mouse button was pressed and
set the var = true
on the doubleclick and mouseup events set the var = false
on the mouse move event ...
if var==true
DoDragDrop(...

it works well, if anyone has the same problem i can email you code extract

thanks john anyway

sam
 
J

John Wood

hmm ok, one thing worth mentioning -- to be consistent with everything else
in windows, you should only initiate the drag when the mouse moves beyond
the SystemInformation.DragSize in pixels from the mouse down position.
 

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