在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
首先建一个Windows应用程序 1 Point mouseOff;//鼠标移动位置变量 2 bool leftFlag;//标记是否为左键 3 private void Form1_MouseDown(object sender, MouseEventArgs e) 4 { 5 if (e.Button == MouseButtons.Left) 6 { 7 mouseOff = new Point(-e.X, -e.Y); //得到变量的值 8 leftFlag = true; //点击左键按下时标注为true; 9 } 10 } 11 12 private void Form1_MouseMove(object sender, MouseEventArgs e) 13 { 14 if (leftFlag) 15 { 16 Point mouseSet = Control.MousePosition; 17 mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置 18 Location = mouseSet; 19 } 20 } 21 22 private void Form1_MouseUp(object sender, MouseEventArgs e) 23 { 24 if (leftFlag) 25 { 26 leftFlag = false;//释放鼠标后标注为false; 27 } 28 }
首先建一个Windows应用程序 1 Point mouseOff;//鼠标移动位置变量 2 bool leftFlag;//标记是否为左键 3 private void Form1_MouseDown(object sender, MouseEventArgs e) 4 { 5 if (e.Button == MouseButtons.Left) 6 { 7 mouseOff = new Point(-e.X, -e.Y); //得到变量的值 8 leftFlag = true; //点击左键按下时标注为true; 9 } 10 } 11 12 private void Form1_MouseMove(object sender, MouseEventArgs e) 13 { 14 if (leftFlag) 15 { 16 Point mouseSet = Control.MousePosition; 17 mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置 18 Location = mouseSet; 19 } 20 } 21 22 private void Form1_MouseUp(object sender, MouseEventArgs e) 23 { 24 if (leftFlag) 25 { 26 leftFlag = false;//释放鼠标后标注为false; 27 } 28 }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论