Here's I wrote some code to move controls on the form
1- Assign (Control_MouseMove, Control_MouseDown, and Control_MouseUp) to the controls you need it movable.
How to make your controls moveable?
ddanbe commented: Great! +6
//This code developed by Ramy Mahrous
//ramyamahrous@hotmail.com
//Its contents is provided "as is", without warranty.
/// <summary>
/// Indicates whether control is pressed by mouse or not
/// </summary>
bool IsDraged = false;
/// <summary>
/// Holds the X-coordinate of the control
/// </summary>
int Control_X = 0;
/// <summary>
/// Holds the Y-coordinate of the control
/// </summary>
int Control_Y = 0;
private void Control_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
IsDraged = true;
Control_X = e.X;
Control_Y = e.Y;
}
}
private void Control_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
IsDraged = false;
}
}
private void Control_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Control active = (Control)sender;
if (IsDraged)
{
active.Left += e.X - Control_X / 12;
active.Top += e.Y - Control_Y / 12;
Control_X = e.X;
Control_Y = e.Y;
}
}
}
persianc# 0 Newbie Poster
cipher_nemo 0 Newbie Poster
vigor 0 Newbie Poster
Ramy Mahrous 401 Postaholic Featured Poster
vigor 0 Newbie Poster
Diamonddrake 397 Master Poster
vigor 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.