Advertisement
deSantoz

Resize / Move borderless form

May 26th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.28 KB | None | 0 0
  1. Public Partial Class Form1
  2.     Inherits Form
  3.  
  4.     Public Sub New()
  5.         InitializeComponent()
  6.         Me.FormBorderStyle = FormBorderStyle.None
  7.         Me.DoubleBuffered = True
  8.         Me.SetStyle(ControlStyles.ResizeRedraw, True)
  9.     End Sub
  10.  
  11.     Private Const cGrip As Integer = 16
  12.     Private Const cCaption As Integer = 32
  13.  
  14.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  15.         Dim rc As Rectangle = New Rectangle(Me.ClientSize.Width - cGrip, Me.ClientSize.Height - cGrip, cGrip, cGrip)
  16.         ControlPaint.DrawSizeGrip(e.Graphics, Me.BackColor, rc)
  17.         rc = New Rectangle(0, 0, Me.ClientSize.Width, cCaption)
  18.         e.Graphics.FillRectangle(Brushes.DarkBlue, rc)
  19.     End Sub
  20.  
  21.     Protected Overrides Sub WndProc(ByRef m As Message)
  22.         If m.Msg = &H84 Then
  23.             Dim pos As Point = New Point(m.LParam.ToInt32())
  24.             pos = Me.PointToClient(pos)
  25.  
  26.             If pos.Y < cCaption Then
  27.                 m.Result = CType(2, IntPtr)
  28.                 Return
  29.             End If
  30.  
  31.             If pos.X >= Me.ClientSize.Width - cGrip AndAlso pos.Y >= Me.ClientSize.Height - cGrip Then
  32.                 m.Result = CType(17, IntPtr)
  33.                 Return
  34.             End If
  35.         End If
  36.  
  37.         MyBase.WndProc(m)
  38.     End Sub
  39. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement