Foros del Web » Programación para mayores de 30 ;) » .NET »

Mover imagen DrapDrop

Estas en el tema de Mover imagen DrapDrop en el foro de .NET en Foros del Web. 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) ...
  #1 (permalink)  
Antiguo 01/02/2011, 14:25
 
Fecha de Ingreso: octubre-2008
Mensajes: 188
Antigüedad: 15 años, 6 meses
Puntos: 3
Mover imagen DrapDrop

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.
  #2 (permalink)  
Antiguo 03/02/2011, 08:03
 
Fecha de Ingreso: octubre-2008
Mensajes: 188
Antigüedad: 15 años, 6 meses
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

Etiquetas: mover
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:23.