Winform 无边框窗口移动自定义边框粗细颜色
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace WinGPChat.master 12 { 13 public partial class formBase : Form 14 { 15 public formBase() 16 { 17 InitializeComponent(); 18 } 19 private Point mPoint = new Point(); 20 private void formBase_Load(object sender, EventArgs e) 21 { 22 this.MouseDown+=formBase_MouseDown; 23 this.MouseMove+=formBase_MouseMove; 24 } 25 26 protected void formBase_MouseMove(object sender, MouseEventArgs e) 27 { 28 if (e.Button == MouseButtons.Left) 29 { 30 Point myPosittion = MousePosition; 31 myPosittion.Offset(-mPoint.X, -mPoint.Y); 32 this.FindForm().Location = myPosittion; 33 } 34 } 35 36 protected void formBase_MouseDown(object sender, MouseEventArgs e) 37 { 38 mPoint.X = e.X; 39 mPoint.Y = e.Y; 40 } 41 42 /// <summary> 43 /// 重写Paint实现细边框 44 /// </summary> 45 /// <param name="e"></param> 46 protected override void OnPaint(PaintEventArgs e) 47 { 48 Pen pen = new Pen(Color.Gray,1); 49 e.Graphics.DrawLine(pen, new Point(0, 0), new Point(this.Width-1, 0)); //上 50 e.Graphics.DrawLine(pen, new Point(0, 0), new Point(0, this.Height-1)); //左 51 e.Graphics.DrawLine(pen, new Point(this.Width-1, 0), new Point(this.Width-1, this.Height-1));//右 52 e.Graphics.DrawLine(pen, new Point(0, this.Height-1), new Point(this.Width-1, this.Height-1));//下 53 base.OnPaint(e); 54 } 55 56 /// <summary> 57 /// 无边框重写点击icon实现窗体最大化和最小化 58 /// </summary> 59 protected override CreateParams CreateParams 60 { 61 get 62 { 63 CreateParams cp = base.CreateParams; 64 cp.Style = cp.Style | 0x20000;//允许最小化操作 65 return cp; 66 } 67 } 68 69 70 } 71 }