| ||||||||
| Home > Software > Drag-n-Drop Using Visual Basic > Example1 For Drag & Drop Operation – Difficulty level: Easy | ||||||||
|
Visual Basic 6 : Drag-n-Drop Tutorial 2.0 Example1 For Drag & Drop Operation – Difficulty level: Easy2.1 Brief details of Example1Let's look at some examples, starting with simple drag and drop operation. Create a Visual Basic project and design a form with control & Drag Drop event procedure as follows In this example an Image control array is created. One has to drag & drop these images to appropriate places
Fig3 Design view of the form for Example1 Form1 has the following details Since both source & target are controls that are part of the control array, the event procedures will have an additional argument that specifies the Index property of the control within the control array. Private Sub Imagedrop_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) If TypeOf Source Is Image Then End Sub In the above drag Drop event Type of Operator checks ,type of source control whether it is a text box control or Label, or a Form itself In the above Drag Drop event it checks whether source is a Image control only then it’s dropped on to the target. Below example explains Mouse move event of the source control Private Sub Imageanimal_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then End Sub When the left mouse button is pressed drag operation is initiated by setting action to vbBeginDrag, on releasing the mouse button we can end drag operation by setting the action to VbEndDrag or we can also cancel the operation by setting the action to VBCancel. below code explains this. Private Sub Imageanimal_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then End Sub Screen Shot for Example1 is as shown below
Fig4 Output Screen for example1 control before being dragged to the destination
Fig5. Output Screen for example1 Control after being dragged to the destination Complete code for the above example is available for download as SimpleDragdropdemo.zip 2.2 Downloadable zip file | ||||||||
| ||||||||
| Home Copyright (C) 2003-2011 TutorialsWeb.com Disclaimer Sitemap | ||||||||