|
-
Aug 28th, 2002, 05:06 PM
#3
Member
.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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|