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)
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)
sender.Location = ControlPosition
Now run the application. and you can move controls while application is running.
Please format your resource.
hello dami. how can we do the same with c#? because i am getting touble doing the same in c#
like it thaks
hi its very cool.. but i want to select many controls by mouse and wanna move simulntanesly .. is there any idea for it?