A Drag and Drop Recycle Bin

 

This is a drag and drop program that resembles a recycle bin . Drag and drop is a common windows application where you can drag and drop an object such as a file into a folder or into a recycle bin. This capability can be easily programmed in visual basic. In this example, we have created a program that can simulate the dragging of the objects into a recycle bin, and burn them.

In this program, you need to insert 6 images into the form: a recycle bin, a burning recycle bin, the fire, and three more images which are to be dragged into the recycle bin. In addition, set all the dragmode of the images (including the fire) to 1(Automatic) so that dragging is enabled, and set the visible property of the burning recycle bin to false at start-up. Besides that, label the tag of fire as fire in its properties window. If you want to have better dragging effects, you need to load an appropriate icon under the dragIcon properties for those images to be dragged. Preferably the icon should be the same as the image so that when you drag the image, it is like you are dragging the image along. The design interface is shown below:

 

The Runtime Interface

 

 

The essential event procedure in this program is as follows:

Private Sub Image4_DragDrop(Source As Control, X As Single, Y As Single)

Source.Visible = False
If Source.Tag = "Fire" Then
Image4.Picture = Image5.Picture
End If

End Sub

Source refers to the image being dragged. Using the code Source.Visible=False means it will disappear after being dragged into the recycle bin (Image4). If the source is Fire, then the recycle will change into a burning recycle bin, which is accomplished by using the code Image4.Picture = Image5.Picture, where Image 5 is the burning recycle bin.

The complete code

Private Sub Form_Click()
Label1.Visible = False
End Sub

Private Sub Image4_DragDrop(Source As Control, X As Single, Y As Single)
Source.Visible = False
If Source.Tag = "Fire" Then
Image4.Picture = Image5.Picture
End If

End Sub

Private Sub instruct_Click()
Label1.Visible = True
End Sub

 

 

[Back to Sample VB Programs]

Copyright ® 2008 Dr.Liew Voon Kiong . All rights reserved |Contact: admin@vbtutor.net

[Privacy Policy]