Hi,
Is there a way to allow the user to move a command button around in a picture box for example. (or a form)?
Printable View
Hi,
Is there a way to allow the user to move a command button around in a picture box for example. (or a form)?
how about setting a right click popup menu to the button..then if they pick "move" from the menu... allow then to click another spot on the form..and set the top / left
or check for a special keycombo... like if they hold SHIFT and click and hold the button...allow a drag/drop.
but..in a nutshell, YES you can let the user move the button
Sure, but be specific about what you want. Do u want the user to b able to drag it? Do you want it to move automatically?
Like this you mean:
VB Code:
Option Explicit Dim intLeftGap As Integer Dim intTopGap As Integer Private Sub Command1_Click() Load Form2 Form2.Show vbModal, Me End Sub Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbRightButton Then intLeftGap = X intTopGap = Y End If End Sub Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbRightButton Then Command1.Left = X + Command1.Left - intLeftGap Command1.Top = Y + Command1.Top - intTopGap End If End Sub
Thanks WokaWidget, that's exactly what I needed. I don't care about the Click event because the user will be only allowed to move the buttons around a picture box.
ok here...
change the Drag mode of the command button to automatic
then in the Dragdrop event of the form.
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Left = X
Source.Top = Y
End Sub
thats it
thanks geoff_xrx. However, the button will be placed according to the mouse_cursors's x and y properties as oppose to the buttons.