开头添加变量:
Point mouseOff;//鼠标移动位置变量
bool leftFlag;//标签是否为左键
事件部分:
1 private void Login_MouseMove(object sender, MouseEventArgs e) 2 { 3 //鼠标指向检测 4 if (leftFlag) 5 6 { 7 8 Point mouseSet = Control.MousePosition; 9 10 mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置 11 12 Location = mouseSet; 13 14 } 15 // 16 } 17 18 private void Login_MouseUp(object sender, MouseEventArgs e) 19 { 20 21 if (leftFlag) 22 23 { 24 25 leftFlag = false;//释放鼠标后标注为false; 26 27 } 28 } 29 30 private void Login_MouseDown(object sender, MouseEventArgs e) 31 { 32 if (e.Button == MouseButtons.Left) 33 34 { 35 36 mouseOff = new Point(-e.X, -e.Y); //得到变量的值 37 38 leftFlag = true; //点击左键按下时标注为true; 39 40 } 41 }
ps:很常用的几串字符。
记住! 记住! 记住!
时间: 2024-10-07 08:05:57