3 Attachment(s)
How to use the drag 'n' drop.
I attached them all at the buttom
This is how to make a button, Command1, move on the form, form1, freally:
You need Command1 and Form1
VB Code:
Dim StartX, StartY
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
StartX = X 'Store button starting location
StartY = Y 'Store button starting location
Command1.Drag vbBeginDrag 'Starts drag
End Sub
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.Drag vbEndDrag 'Ends Drag mode
End Sub
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move X - StartX, Y - StartY 'Move the control to droped location
End Sub
This is how to make that if the button has been droped on the label, Label1, it will reposion itself on it, mostly used on games that want you to limit that place a control can be droped on.
You need Command1 and Label1, make sure you have the label one in a diffrent color so you can see it:
VB Code:
Dim StartX, StartY
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
StartX = X 'Store button starting location
StartY = Y 'Store button starting location
Command1.Drag vbBeginDrag 'Starts drag
End Sub
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.Drag vbEndDrag 'Ends Drag mode
End Sub
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move X - StartX, Y - StartY 'Move the control to droped location
End Sub
Private Sub Label1_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move Label1.Left, Label1.Top 'Move the control to droped location
End Sub
This is how to change the control veriable according to where to posion it on:
You need a Command1, Label1, and Label2. Change label1 background to blue and label2 to red.
VB Code:
Dim StartX, StartY
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
StartX = X 'Store button starting location
StartY = Y 'Store button starting location
Command1.Drag vbBeginDrag 'Starts drag
End Sub
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.Drag vbEndDrag 'Ends Drag mode
End Sub
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move X - StartX, Y - StartY 'Move the control to droped location
Source.BackColor = Me.BackColor
End Sub
Private Sub Label1_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move Label1.Left, Label1.Top 'reposion the control posion to the label
Source.BackColor = Label1.BackColor ' Change the control background
End Sub
Private Sub Label2_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move Label2.Left, Label2.Top 'reposion the control posion to the label
Source.BackColor = Label2.BackColor ' Change the control background
End Sub