VB2019 VB2017 VB2015 VB2013 VB2012 VB2010 VB2008 VB6 VB Sample Codes 中文VB About Us

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 create a program that simulates the dragging of the objects into a recycle bin and burns 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. 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 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 Design Interface

The Video Demo

The 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


 


Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy