关于C#无边框窗体的移动怎么实现
1个回答
展开全部
那就得自己写窗体移动代码了
鼠标左键按下事件:记录当前鼠标位置 A 并设置一个bool变量记录是否按下了鼠标左键isclick
鼠标移动事件:先判断isclick是否为true:获取当前鼠标位置B A减B的距离就是窗体移动的距离
鼠标左键松开事件:isclick=false
bool isclick;
Point formpoint;
Point mousepoint;
private void panel_top_MouseDown(object sender, MouseEventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
if (e.Button == MouseButtons.Left)
{
isclick = true;
formpoint = this.Location;
mousepoint = Control.MousePosition;
}
}
}
private void panel_top_MouseUp(object sender, MouseEventArgs e)
{
isclick = false;
}
private void panel_top_MouseMove(object sender, MouseEventArgs e)
{
int newx = 0;
int newy = 0;
if (isclick && this.WindowState == FormWindowState.Normal)
{
Point temp = Control.MousePosition;
newx = mousepoint.X - temp.X;
newy = mousepoint.Y - temp.Y;
this.Location = new Point(formpoint.X - newx, formpoint.Y - newy);
}
}
写得有点凌乱,将就看吧
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询