没有边框的窗体怎么移动?其实方法有很多,下面介绍一种用控件来移动窗体,Panel或PictureBox都可。主要设置控件的MouseDowm和MouseLeave事件。
第一步:窗体设计
窗体最上面是一个panel1
窗体最下面是一个Panel3,只显示最上面一条线
第二步:panel移动窗体实现代码
MouseDown事件
MouseLeave事件
#region 移动窗体Point downPoint;private void panel1_MouseDown(object sender, MouseEventArgs e){downPoint = new Point(e.X, e.Y);}private void panel1_MouseMove(object sender, MouseEventArgs e){if (e.Button == MouseButtons.Left){this.Location = new Point(this.Location.X + e.X - downPoint.X,this.Location.Y + e.Y - downPoint.Y);}}#endregion
如何实现panel只显示最上面一条线?
Paint事件
//重绘panel3,只显示最上面一条直线private void panel3_Paint(object sender, PaintEventArgs e){ControlPaint.DrawBorder(e.Graphics,this.panel3.ClientRectangle,Color.Lavender,1, ButtonBorderStyle.Dashed,Color.Gray,1,ButtonBorderStyle.Solid,Color.Lavender,1,ButtonBorderStyle.Dashed,Color.Lavender,1,ButtonBorderStyle.Dashed);}