[RESOLVED] Dragging and dropping..
Would it be possible to have it so there could be a picture on your form, you drag and drop it somewhere else and the original picture stays there but a new one which is identical appears in the place you dropped it and you could do it again to create a third one and then do it over and over again?
Re: Dragging and dropping..
You can do it by creating a control array of the PictureBox
Try this:
VB Code:
Option Explicit
'[b] Add a picturebox in the form and set its Index = 0[/b]
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Picture1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
If Index = 0 Then
Load Picture1(Picture1.UBound + 1)
Picture1(Picture1.UBound).Visible = True
Picture1(Picture1.UBound).ZOrder 0
'
ReleaseCapture
SendMessageLong Picture1(Picture1.UBound).hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End If
End If
End Sub
(Modification of this code)
Re: Dragging and dropping..
sure u can.
'add a picture box named picture1 and set index=0
Option Explicit
Dim picCount As Integer
Dim dx As Single, dy As Single
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Load Picture1(picCount + 1)
Picture1(picCount + 1).Left = X - dx
Picture1(picCount + 1).Top = Y - dy
Picture1(picCount + 1).Visible = True
picCount = picCount + 1
End Sub
Private Sub Picture1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
dx = X
dy = Y
End Sub
hope this code helps. ^^