Ver Mensaje Individual
  #2 (permalink)  
Antiguo 03/02/2011, 08:03
truskyvb
 
Fecha de Ingreso: octubre-2008
Mensajes: 188
Antigüedad: 16 años, 1 mes
Puntos: 3
De acuerdo Solucionado Mover imagen DrapDrop

Supongo que no es un código muy ortodoxo pero funciona.

Controles:
PictureBox1 con una imagen transparente PNG
PictureBox2 sin imagen. Es el control de destino

Agrego como recurso la imagen del PictureBox1 en formato ICO (imgcur.ico)



Public Class Form1

Dim m_MouseIsDown As Boolean


Private Sub Form1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter

e.Effect = DragDropEffects.Move

End Sub



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


PictureBox2.AllowDrop = True
PictureBoxcursor.Cursor = New Cursor(My.Resources.imgcur.Handle)

End Sub


Private Sub PictureBox1_GiveFeedback(ByVal sender As Object, ByVal e As System.Windows.Forms.GiveFeedbackEventArgs) Handles PictureBox1.GiveFeedback


imgcur.UseDefaultCursors = False

If ((e.Effect And DragDropEffects.Move) = DragDropEffects.Move) Then

Cursor.Current = New Cursor(My.Resources.imgcur.Handle)

Else

Cursor.Current = System.Windows.Forms.Cursors.Default
End If

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

m_MouseIsDown = True
End If

End Sub


Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

If m_MouseIsDown Then

PictureBox1.DoDragDrop(PictureBox1.Image, DragDropEffects.Copy Or _
DragDropEffects.Move)
End If

m_MouseIsDown = False

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

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
Label2.Visible = False
End If

End Sub

End Class