how do i drag a control, particularly, a picturebox at runtime??
Printable View
how do i drag a control, particularly, a picturebox at runtime??
Try this basic sample and let me know if works for you:
Code:Option Explicit
Dim intY As Integer
Dim intX As Integer
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
intX = X
intY = Y
Picture1.Drag vbBeginDrag
End Sub
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move X - intX, Y - intY
Source.Drag vbEndDrag
End Sub
Thanks Rhino, it sometimes work and sometimes not but anyway, i can modify it myself.
Thanx for the Help
Oh, that's because you need to detect actual position of mouse pointer - if it is over picturebox's original position then using sample I posted dragdrop won't occur so you need a bit more coding (left that part for you ;) ).