C#无边框窗体代码问题??????????????????
C#无边框窗体代码问题
private Point mouse_offset;
private void form_MouseDown(object sender, EventArgs e)
{
mouse_offset = new Point(-e.X, -e.Y);
}
private void form_MouseMove(object sender, EventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouse_offset.X, mouse_offset.Y);
this.Location = mousePos;
}
}
报错错误 1 “System.EventArgs”并不包含“X”的定义 d:\test\vc\WindowsApplication6\WindowsApplication6\Form1.cs 25 41 WindowsApplication6
错误 2 “System.EventArgs”并不包含“Y”的定义 d:\test\vc\WindowsApplication6\WindowsApplication6\Form1.cs 25 47 WindowsApplication6
错误 3 “System.EventArgs”并不包含“Button”的定义 d:\test\vc\WindowsApplication6\WindowsApplication6\Form1.cs 30 19 WindowsApplication6
我该怎么改?? e.X e.Y Button怎么定义 书上面没写定义啊
[解决办法]
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;
}
[解决办法]
呃,又是移动无边框窗体的问题,把几个鼠标按键事件处理好就行了,唯一的技巧就是坐标的计算问题,实在简单的不行了,都懒得说了。