.NET 追寻足迹

C# 之路

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

窗体没有标题的情况下

代码
private Point mousePoint;
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Top = Control.MousePosition.Y - mousePoint.Y;
this.Left = Control.MousePosition.X - mousePoint.X;
}
}

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.mousePoint.X = e.X;
this.mousePoint.Y = e.Y;
}
}

 

如果窗体有标题
Top -= SystemInformation.CaptionHeight;

如果有边框
Top -= SystemInformation.FormBorderSize.Height
Left -= SystemInformation.FormBorderSize.Width
posted on 2010-04-03 14:45  绿水青山  阅读(436)  评论(0编辑  收藏  举报