窗口标题栏隐藏后 无法在拖动
需要自己获取移动坐标来设置窗口位置
//外部需要两个集变量
private Point mouseOff;//鼠标移动位置变量
private bool leftFlag;//鼠标是否为左键
//鼠标按下事件
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y);//获得当前鼠标的坐标
leftFlag = true;
}
}
//鼠标移动事件
private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;//获得移动后鼠标的坐标
mouseSet.Offset(mouseOff.X, mouseOff.Y);//设置移动后的位置
Location = mouseSet;//窗口为移动值
}
}
//鼠标放开事件
private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;
}
}
标签:随意,leftFlag,窗口,鼠标,C#,private,mouseOff,移动 From: https://www.cnblogs.com/Hello233/p/16705064.html