You can do this by setting a variable to detect when you're in 'design'
mode and then catching the mouse down event to select which button to move
and then catching the form_mousemove event to change the location of the
button. here's a quick example.
open a new windows app and add 1 checkbox and 1 button. then add the
following code. Run it. Click the checkbox then click the button and move
the mouse around. Click the mouse again and the button stays where you
clicked:
Public down As Boolean = False
Public ReadyToMove As Boolean = False
Public ButtonToMove As Button
Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles CheckBox1.CheckedChanged
'if you're in design mode
If CheckBox1.Checked = True Then
down = True
Else
down = False
ReadyToMove = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If down = True Then
ButtonToMove = Button1
ReadyToMove = True
End If
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If down And ReadyToMove Then
ButtonToMove.Location = New Point(Cursor.Current.Position.X -
Form1.ActiveForm.Location.X, Cursor.Current.Position.Y -
Form1.ActiveForm.Location.Y)
End If
End Sub
Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
If down And ReadyToMove Then
ReadyToMove = False
End If
End Sub
For a certain app, I'd like the user to be able to move buttons around (I
mean physically move them). The reason isn't really important, but it has
to do with an organizational layout. Anyway, it would be cool if the user
could click a "mode" button which almost makes a portion of the form in
"design view" (showing a grid would be cool too) and lets them move the
buttons around. Seeing code-behind is not what I want here. Just moving
them around.
In a form event, I would then capture the new coordinates for all of the
buttons and save them to a database or XML. Then at next form load, replay
the new locations.
Any hints?
thanks,
Eric