日期:2014-05-18 浏览次数:21454 次
private void Form1_MouseDown(object sender, MouseEventArgs e) { t = 1; x = e.Location.X; y = e.Location.Y; } private void Form1_MouseMove(object sender, MouseEventArgs e) { if(t==1) { Location = new Point(Location.X + (e.Location.X - x), Location.Y + (e.Location.Y - y)); } } private void Form1_MouseUp(object sender, MouseEventArgs e) { t = 0; }
------解决方案--------------------
35. private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { 36. thisIsMove = true; 37. //当鼠标点下时 记录想当前的状态 38. sx = MousePosition.X; 39. sy = MousePosition.Y; 40. l = this.Left; t = this.Top; 41. } 42. 43. private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { 44. if (thisIsMove) {//如果为true则移动窗体 45. //当前鼠标的位置与点下的是鼠标坐标的差值加上原来窗体的坐标就是现在移动的位置 46. this.Left = MousePosition.X - sx + l; 47. this.Top = MousePosition.Y - sy + t; 53. } 54. } 55. 56. private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { 57. thisIsMove = false; 58. }
------解决方案--------------------