Este código mueve un PicturBox1 que al pasar sobre el PictureBox2, le “tras-pasa” su imagen.
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox2.AllowDrop = True
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If Not PictureBox1.Image Is Nothing Then
PictureBox1.DoDragDrop(PictureBox1.Image, DragDropEffects.Copy Or
DragDropEffects.Move)
End If
End Sub
Private Sub PictureBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragEnter
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
' Check for the CTRL key.
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 PictureBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop
PictureBox2.Image = e.Data.GetData(DataFormats.Bitmap)
If Not e.KeyState = 8 Then
PictureBox1.Image = Nothing
End If
End Sub
End Class
El problema es que no consigo mover el PictureBox1 uno cuando lo arrastro.
Si pongo en PictureBox1_MouseDown el código de arrastre que sigue, tampoco:
If e.Button = Windows.Forms.MouseButtons.Left Then
PictureBox1.Capture = False
Dim msg As Message = _
Message.Create(PictureBox1.Handle, WM_NCLBUTTONDOWN, _
New IntPtr(HTCAPTION), IntPtr.Zero)
Me.DefWndProc(msg)
End If
Public Class Form1:
Public Const WM_NCLBUTTONDOWN = &HA1
Public Const HTCAPTION = 2
Tal parece que o mueve la imagen o mueve el efecto, pero las dos cosas a la vez no.
Espero haberlo explicado bien. Si podéis darme alguna idea, os lo agradezco.