关于C#无边框窗体的移动怎么实现
答案:1 悬赏:40 手机版
解决时间 2021-04-05 18:34
- 提问者网友:焚苦与心
- 2021-04-04 23:46
关于C#无边框窗体的移动怎么实现
最佳答案
- 五星知识达人网友:想偏头吻你
- 2021-04-05 00:42
那就得自己写窗体移动代码了
鼠标左键按下事件:记录当前鼠标位置 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);
}
}写得有点凌乱,将就看吧
鼠标左键按下事件:记录当前鼠标位置 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);
}
}写得有点凌乱,将就看吧
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯