drag and drop problem

S

Sam Martin

Hi all

I've got a custom control in which I catch the DoubleClick event .. no
probs.

I've just used the control on a form and implemented drag and drop
functionality, i.e. on the MouseDown event (handled in the form) I check to
make sure the left mouse button is pressed, the initiate the drag by calling
the DoDragDrop.. This is textbook stuff, if fact straight from the MS KB
article.

But the problem is now that the double click event isn't firing.
Understandably, but without coding the drag drop manually, or coding the
double click in the control (which I'm guessing everyone doesn't do) - how
do I resolve this?

Any help would be appreciated,

Thanks in advance

Sam Martin
 
B

Bob Powell [MVP]

It's probably best to initiate drag and drop in the mousemove on condition
that the mouse button is down. The user has to make an effort to catch and
drag an item to initiate DD.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Image transition effects, automatic persistent configuration and
design time mouse operations all in April's issue of Well Formed
http://www.bobpowell.net/wellformed.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41
 
L

Lloyd Sheen

Try the following, makes sure there is an actual drag from the control:

First section is to get mouse coordinates when mouse is down.

Private Sub lstObjects_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lstObjects.MouseDown
mbDragging = True
miX = e.X
miY = e.Y
End Sub

Second section is to reset when mouse button is released (no D/D).
Private Sub lstObjects_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lstObjects.MouseUp
If mbDragging Then
mbDragging = False
miX = 0
miY = 0
End If
End Sub

Third section is on the mouse move, it detects whether the mouse was moved
by user or by accident (configurable). Then sets the object and starts drag
and drop:

Private Sub lstObjects_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lstObjects.MouseMove
If mbDragging Then
If Abs(e.X - miX) > 3 Or Abs(e.Y - miY) > 3 Then
Dim poTmp As New DataObject
Dim poFinder As ObjectFinder
If lstObjects.SelectedItems.Count = 0 Then Exit Sub
poFinder = CType(lstObjects.SelectedItems.Item(0).Tag, ObjectFinder)
poFinder.ServerObject.SyntaxEditor = Me.SqlEditor
If Me.MouseButtons = MouseButtons.Left Then
poTmp.SetData("Object", False, poFinder)
Else
poTmp.SetData("RMB", False, poFinder)
End If
Me.DoDragDrop(poTmp, DragDropEffects.All)
Else
Exit Sub
End If
End If
End Sub

Lloyd Sheen
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi guys,
Third section is on the mouse move, it detects whether the mouse was moved
by user or by accident (configurable). Then sets the object and starts drag
and drop:

This is the part, which most of the programmers miss. Indeed the mouse has
to be away of the point where the mouse button was pressed in order to
consider the operation as moving (or in this case as a D'n'D)

The best I believe is to use what is set globally for the system.
That's why my suggestion is to check SystemInformation.DragSize. If the
mouse is moved that amount of pixels since the button was pressed it can be
considered as D'n'D operation.
 

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