private Point p;
//窗体点击事件
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
//获取鼠标点击的坐标
p = new Point(e.X,e.Y);
}
//鼠标在窗体移动事件
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
//判断按下的是否为鼠标左键
if (e.Button == MouseButtons.Left)
{
//窗体位置坐标=窗体在屏幕的坐标+鼠标的坐标-鼠标在窗体内点击的坐标
this.Location = new Point(this.Location.X + e.X - p.X,
this.Location.Y + e.Y - p.Y);
}
}
winform无边框窗体移动
最新推荐文章于 2024-04-07 13:42:14 发布