article

Make your own Drag & Drop

Email
Submitted on: 9/5/2018 5:20:13 PM
By: ICE 
Level: Beginner
User Rating: Unrated
Compatibility: VB 6.0
Views: 1214
author picture
 
     this is a full text tutorial that will help and teach lots how to make Drag & Drop Programs... This is a good base to start with an built up to making a chess game ,,,, Let me know how it goes and what you think of this.....

 
				 In this I am going to walk you through making your own VB6 Drag-&-Drop Program.
 I will do my best to make it easy to understand & to follow along.
 First lets just touch on some things you should know, For example,
 The diffrence between the Source & the Target in a Drag-&-Drop Program
 There's a difference between the DragOver event & the DragDrop event.
 In a Drag & Drop program a object is moved from 1 place to another
 The object being moved (dragged) is called the "source". The place it is
 being dragged to is called the "target"
 Here is a small short quick example of that. Open a new form,
 Add 2 icons to the form, 1 say is some kind of paper,
 The other could be a waste can or a paper shredder.
 The paper would be the "Source", To make the source moveable,
 Set its "DragMode property" to 1 - Automatic,
 And set its DragIcon property yo display an icon, you will only see a outline
 of it when you drag it.
 As you drag the icon across the form, Events are jappening. The events are
 for rhe target not the scorce. As you Drag the icon across the form, the form's
 "DragOver event" occurs. If you drag the icon across a control like Command1
 button, the command button's DragOver event occurs. As long as keep moving
 while you kssp the mousebutton down, DragOver events happen for the form
 and every control you move over. When you release the mousebutton with the
 icon over a control, the control's "DragDrop" event happens: But if you re-lease
 the mouse button over the form, the form's DragDrop event happens.
 That means any drag & drop actions. multiple DragOver events may happen.
 Only 1 DragDrop event happens when the action is complete. All the events 
 happen to the target objects, Mot to the source object.
 NOTE: You can also code for events that happen for the source object, like
 the Click event & the MouseDown, MouseUp & MouseMove events.
 That brief introduction focused on the events for the target objects.
 Now this example you'll denelope a small applicarion that lets the user drag
 a plane icon intia hangar (use a picture box to keep it simple)
 You should have 2 plane icons and a picturebox on your form & 1 plane should
 be in the picturebox (the picture box is the target),,,
 I make a lot of my own icons, Hell 10 or so years ago I made a Tetris game for
 a woman an asked her for a pic of herself so I could make it into a icon & put
 it on the Tetris game for her, She loved it when she saw it.
 OK back to the Drag & Drop application now.
 The Form should have 1 PictureBox on it (Name it "Target")
 There should be a PlaneParked in the taget, it should be Not Visible
 There should also be another plane on the form, it should be Visible.
 Now that you should have your form pretty much set up, an almost ready to
 test to see if when you drag the plane over the picturebox that it disappears
 behind the control (cause of the way graphic controls are layered on rhe form)
 Put a label under the PictureBox set its caption to "Hangar"
 Lets set some Property's now..... 
 Fotm Name: frmPlane
 Caption: Fly the Plane to the Hangar
 The Plane on the form (Not the 1 in the picturebox)
 Name: imgPlane
 Stretch: TRUE
 Picture: Plane.ico
 DragIcon: Plane.ico
 DragMode: 1 - Automatic
 Now lets do the plane that's in the Hangar
 Name: imgPlaneParked
 Stretch: TRUE
Picture Plane.ico
 Visible: False
 Set the Name for the PictureBox to,,,, picHangar
 The label should say Hangar
There is a reason that you should have all the names an other peoperty's
 set as I put them, That is so they will fit the code perfecttly 
 And we will be writing the code next....
 Before writing the code Click the Run & drag the plan to the Hangar
 You should see an Icon as you drag & the original image can still
 be seen, The next step will make the source image invisible
 when you start to drag the image across the form
 Code the Drag Action....
 In the code window, click on Form for the object & DragOver
 for the procedures
 Code the following remark & line of code in the Form_DrafOver 
 event.
 ' Make the Plane iinvisible
 imgPlane.Visible = False
 Run the program & see if when youi start dragging the plane that
 the original should dissapear & it should look like you're actually dragging
 the image, Try dropping it anywhere, it disappears doesn't it...
 Now it's time to take care of the drop operation
 Click on the stop button....
 Lets code the Drop Operation
 Code the DragDrop event for the picturebox (picHangar).
 Private Sub picHangar_DragDrop(Source As Control, X As Single, Y As Single)
 ' Good Drop
 imgPlaneParked.Visible = True
 End Sub
 Code the DragDrop event for the form
 Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
 ' Bad Drop
 imgPlane.Visible = True
 End Sub
 Code a DragDrop event for the label control. If the user drops the plane
 on the label, it's another bad drop.
 Private Sub Label1_DragDrop(Source As Control, X As Single, Y As Single)
 ' Bad Drop
 imgPlane.Visible = True
 End Sub
 ' Let me know how it goes


Other 34 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.