3
Answers

Change form location with draging a control

Photo of Majid Kamali

Majid Kamali

14y
11.7k
1
Hi.
I created a borderless form and a MenuStrip docked on top of it that has a close and a minimize button.
How can I change form location when I drag that MenuStrip control?
Thanks :-)

Answers (3)

1
Photo of Frogleg
NA 7.9k 33k 14y

try this
public partial class Form1 : Form
{
bool _mouseDown = false;
Point startPt;
public Form1()
{
InitializeComponent();
}
private void menuStrip1_MouseDown(object sender, MouseEventArgs e)
{
_mouseDown =
true;
startPt = e.Location;
}
private void menuStrip1_MouseMove(object sender, MouseEventArgs e)
{
if (_mouseDown == true)
{
Point currentPos = PointToScreen(e.Location);
Location =
new Point(currentPos.X - startPt.X, currentPos.Y - startPt.Y);
}
}
private void menuStrip1_MouseUp(object sender, MouseEventArgs e)
{
_mouseDown =
false;
}
}
Accepted
0
Photo of Suthish Nair
NA 31.7k 4.6m 14y

again Frogleg, thumps up :)

good example..
0
Photo of Majid Kamali
NA 315 213.4k 14y
Thank you :-)