日期:2014-05-18 浏览次数:21021 次
private Point mouse_offset;
private void form_MouseDown(object sender, [color=#FF0000]EventArgs [/color]e)
{
mouse_offset = new Point(-e.X, -e.Y);
}
private void form_MouseMove(object sender, [color=#FF0000]MouseEventArgs [/color]e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouse_offset.X, mouse_offset.Y);
this.Location = mousePos;
}
}
------解决方案--------------------
MouseDonw 事件是有MouseEventArgs e 参数的。你检查一下,代码写错了。
------解决方案--------------------
若是无边框窗体的移动.
bool beginMove=false;
int currentXPosition = 0;
int currentYPosition = 0;
private void Fomr_MouseMove(object sender, MouseEventArgs e)
{
if (beginMove)
{
this.Left += MousePosition.X - currentXPosition;
this.Top += MousePosition.Y - currentYPosition;
currentXPosition = MousePosition.X;
currentYPosition = MousePosition.Y;
}
}
private void Fomr_MouseDown(object sender, MouseEventArgs e)
{
beginMove = true;
currentXPosition = MousePosition.X;
currentYPosition = MousePosition.Y;
}
private void Fomr_MouseUp(object sender, MouseEventArgs e)
{
beginMove = false;
}
------解决方案--------------------
呃,又是移动无边框窗体的问题,把几个鼠标按键事件处理好就行了,唯一的技巧就是坐标的计算问题,实在简单的不行了,都懒得说了。