Hacer Drag and Drop de un control (ejemplo de un PictureBox)


Truco de Visual Basic 6.0 - Hacer Drag and Drop de un control (ejemplo de un PictureBox)


En Visual Basic 6.0 realizar un Drag and Drop no tiene mucha dificultad.


En un formulario, añadir un PictureBox con una imagen cualquiera y escribir el siguiente código:

Private DragX As Integer
Private DragY As Integer

Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move (X - DragX), (Y - DragY)
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer,
X As Single, Y As Single)
'Si el boton del raton es el derecho, no hacemos nada
If Button = 2 Then Exit Sub
Picture1.Drag 1
DragX = X
DragY = Y
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer,
X As Single, Y As Single)
Picture1.Drag 2
End Sub


Más trucos de Trucos de Visual Basic 6.0

Trucos más leídos