-
Drag and Drop
What is the easiest way to drag an object? For example I am trying to use an Picture with the airplane icon (a project I had to do in VB5) and have the user drag it over labels. I know this was very simple in previous versions of VB. I am going back through my old vb books and see there is a drag mode and I wasn't sure if that is possible in vb.net.
Looks like I need to throw away my old vb books from 4,5, and 6.
By the way what is the best book to learn vb.net Such as easy stuff like objects, small graphics, and of course databases.
Looks like I will need to pick up a new book.
Thanks
Dan Schuessler
-
vb.net book
I use "Professional VB.NET 2nd Ed." by Barwell, Case, Forgey, et. al, Wrox, ISBN: 1861007167
I must say, I think it is a very good book...
It is based upon .NET v1.0 (the final release)
suc6
Dozo
-
.Net drag-drop operation is a little bit different with VB6. It's more like the OLE drag-drop operation in previous versions of VB. To start a drag-drop operation, simply call the DoDragDrop method of your desired control. First Argument is the data that you want to drag-drop operation contains, second one is allowed action (or actions), such as copy operation or move operation. To make your controls response to this operation, set the ‘AllowDrop’ property of them to True, then handle the ‘DragEnter’ event to accept or deny drop during operation. Handle the ‘DragDrop’ event to do the final job, See:
Private Sub myPictureBox_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles myPictureBox.MouseDown
If (myPictureBox.Image Is Nothing) = False Then
Dim tmpBitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(myPictureBox.Image)
myPictureBox.DoDragDrop(tmpBitmap, System.Windows.Forms.DragDropEffects.Copy)
End If
End Sub
Private Sub myLabel_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles myLabel.DragEnter
If e.Data.GetDataPresent(GetType(System.Drawing.Bitmap)) = True Then
e.Effect = System.Windows.Forms.DragDropEffects.Copy
Else
e.Effect = System.Windows.Forms.DragDropEffects.None
End If
End Sub
Private Sub myLabel_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles myLabel.DragDrop
If e.Data.GetDataPresent(GetType(System.Drawing.Bitmap)) = True Then
myLabel.Image = CType(e.Data.GetData(GetType(System.Drawing.Bitmap)), System.Drawing.Image)
End If
End Sub
This will copy the 'Image' property of a picturebox (myPictureBox) to 'Image' property of a label (myLabel) with a drag-drop operation.
Good Luck.