"Generic" Drag and Drop Difficulties

colossus1958

Member
Joined
Sep 7, 2008
Messages
10
Programming Experience
Beginner
Howdy,

Back again with the usual noob stuff. Can't seem to find out how to make "generic" drag and drop setup within my app. I've seen mosy of the posts on the subject but they all seem to imply that I'm going to have to write a set of subs (MouseDown, MouseMove, DragDrop, etc.) for each picturebox on my main form. Surely this can't be right? I have over 40 PB's on the form! Please help.

P.S. Thanx for the earlier assistance (since I forgot to tell you then).

Waiting...:)
 
Well you could write one sub for each MouseDown, MouseUp, MouseMove, etc then when you create the PB's you use the AddHandler statement to link the each event to the corresponding sub.

In each sub, be sure to use the sender object to reference the control, no hard coded controls.
 
This is what I thought. But the code inside the subs is picturebox specific (or at least everything I've seen has been). How do I get around this obstacle?
 
In an event handler the 'sender' parameter IS the object that raised the event. You can use the same method to handle the MouseDown event for 40 PictureBoxes and you can reference the actual PictureBox object you moused down on via the 'sender' parameter:
VB.NET:
Private Sub PictureBox_MouseDown(ByVal sender As Object, _
                                 ByVal e As MouseEventArgs)
    Dim pb As PictureBox = DirectCast(sender, PictureBox)

    'Use pb here.
End Sub
The same principle holds for any event, which is one of the reasons that that pattern is used. It doesn't even have to be all the same events you're handling, as long as the event signatures match.
 
to Further the question about this topic, how to drag-drop between two datagrids on 2 different MDI Child forms??? i tried, but it took me... whew... thanks...
 
Back
Top