Advertisement
tolikpunkoff

FormBorderStyle None form resize and move

Jan 27th, 2018
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. public frmTest()
  2.         {
  3.             InitializeComponent();
  4.  
  5.             this.FormBorderStyle = FormBorderStyle.None;
  6.             this.DoubleBuffered = true;
  7.             this.SetStyle(ControlStyles.ResizeRedraw, true);
  8.         }
  9.  
  10.         private const int cGrip = 16;      // Grip size
  11.         private const int cCaption = 24;   // Caption bar height;
  12.  
  13.         protected override void OnPaint(PaintEventArgs e)
  14.         {
  15.             Rectangle rc = new Rectangle(this.ClientSize.Width - cGrip, this.ClientSize.Height - cGrip, cGrip, cGrip);
  16.             ControlPaint.DrawSizeGrip(e.Graphics, this.BackColor, rc);
  17.             rc = new Rectangle(0, 0, this.ClientSize.Width, cCaption);
  18.             e.Graphics.FillRectangle(Brushes.DarkBlue, rc);
  19.         }
  20.  
  21.         protected override void WndProc(ref Message m)
  22.         {
  23.             if (m.Msg == 0x84)
  24.             {  // Trap WM_NCHITTEST
  25.                 Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16);
  26.                 pos = this.PointToClient(pos);
  27.                 if (pos.Y < cCaption)
  28.                 {
  29.                     m.Result = (IntPtr)2;  // HTCAPTION
  30.                     return;
  31.                 }
  32.                 if (pos.X >= this.ClientSize.Width - cGrip && pos.Y >= this.ClientSize.Height - cGrip)
  33.                 {
  34.                     m.Result = (IntPtr)17; // HTBOTTOMRIGHT
  35.                     return;
  36.                 }
  37.             }
  38.             base.WndProc(ref m);
  39.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement