DragDrop using cursor thumbnail image
This code allows an image to be dragdrop between PictureBox1 (pb1) and PictureBox2 (pb2). This uses a cursor which becomes a thumbnail image during the drag event, of the image being dragged.
Code:
Code:
Dim MouseIsDown As Boolean = False
Private Sub pb1_MouseDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles pb1.MouseDown
MouseIsDown = True
End Sub
Private Sub pb1_MouseMove(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles pb1.MouseMove
If MouseIsDown Then
If pb1.Image Is Nothing Then Exit Sub
pb1.DoDragDrop(pb1.Image, DragDropEffects.Move)
Else
MouseIsDown = False
End If
End Sub
Private Sub pb1_GiveFeedback(ByVal sender As Object, _
ByVal e As System.Windows.Forms.GiveFeedbackEventArgs) Handles pb1.GiveFeedback
e.UseDefaultCursors = False
Dim myPic As New Bitmap(CType(sender, PictureBox).Image)
cursorImage = myPic.GetThumbnailImage(25, 25, Nothing, IntPtr.Zero)
Cursor.Current = New Cursor(CType(cursorImage, System.Drawing.Bitmap).GetHicon())
End Sub
Private Sub pb2_DragEnter(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles pb2.DragEnter
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
If e.KeyState = 9 Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.Move
End If
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub pb2_DragDrop(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DragEventArgs) Handles pb2.DragDrop
pb2.Image = e.Data.GetData(DataFormats.Bitmap)
End Sub