在窗口应用程序中,使用c#i创建了一个表单并将可见的false最小化,最大化按钮和formborder设置为none,我将一个面板放在表单的顶部,在该面板中我放置关闭,最小化按钮。现在我如何拖动窗体。任何参考请。我的代码是
this.ControlBox = false;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.FormBorderStyle = FormBorderStyle.None;
谢谢。
答案 0 :(得分:0)
只需为MouseDown
MouseMove
,MoueUp
和Panel
个事件
bool MouseDownFlag = false;
Point start = new Point(0, 0);
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
start = new Point(e.X, e.Y);
MouseDownFlag = true;
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (MouseDownFlag)
{
Point newPoint = new Point();
newPoint.X = this.Location.X - (start.X - e.X);
newPoint.Y = this.Location.Y - (start.Y - e.Y);
this.Location = newPoint;
}
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
MouseDownFlag = false;
}