Move Controls With Mouse.
Hello Friends,
Here is a very simple procedure to move controls runtime. it is useful when we need to move a control while application is running. Control.MouseDown and Control.MouseMove are used to do this work done. And Controls will be movable runtime as smooth as it can be moved at design time.
To have this done, start a new project with VB
Project name by default will be WindowsApplication1
Now Create few controls from tool bar
Button1, TextBox1, ComboBox1, PictureBox1
and write code as below.
Public Class Form1
Dim cordinates As Point
Private Sub Control_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown, Button1.MouseDown, ComboBox1.MouseDown, TextBox1.MouseDown
cordinates = New Point(-e.X, -e.Y)
End Sub
Private Sub Control_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseMove, Button1.MouseMove, ComboBox1.MouseMove, TextBox1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim ControlPosition As Point = Me.PointToClient(MousePosition)
ControlPosition.Offset(cordinates.X, cordinates.Y)
sender.Location = ControlPosition
End If
End Sub
End Class
Now run the application. and you can move controls while application is running.
Please format your resource.