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 the following example, I am creating a simulation of dragging the objects into a recycle bin, then drop a fire and burn them away.
In this program, I put 6 images on the form, one of them is a recycle bin, another is a burning recycle bin , one more is the fire, and three more images. In addition, set the property dragmode of all the images( including the fire) that are to be dragged to 1(Automatic) so that dragging is enabled, and set the visible property of burning recycle bin to false at start-up. Besides, label the tag of fire as fire in its properties windows. 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
Image4.Picture = Image5.Picture
End If
End Sub
Source refer to the image to be 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 bin will changed into a burning recycle bin , which is accomplished by using the code Image4.Picture = Image5.Picture, where Image 5 is the burning recycle bin.
For details of this program, please refer to my game and fun programming page or click this link, Recycle Bin.
http://www.vbtutor.net/vb6/vbtutor.html
No comments:
Post a Comment