












先声明
1
private Point mousePoint;
1
private void Form1_MouseMove(object sender, MouseEventArgs e)
2
{
3
if (e.Button == MouseButtons.Left)
4
{
5
this.Top = Control.MousePosition.Y - mousePoint.Y;
6
this.Left = Control.MousePosition.X - mousePoint.X;
7
}
8
}
9
10
private void Form1_MouseDown(object sender, MouseEventArgs e)
11
{
12
if (e.Button == MouseButtons.Left)
13
{
14
this.mousePoint.X = e.X;
15
this.mousePoint.Y = e.Y;
16
}
17
}
如果窗体有标题
Top -= SystemInformation.CaptionHeight;
如果有边框
Top -= SystemInformation.FormBorderSize.Height
Left -= SystemInformation.FormBorderSize.Width
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。