question

TwistyNado-9936 avatar image
0 Votes"
TwistyNado-9936 asked Viorel-1 edited

Resizing a Windows Forms border if the border is set to None.

Hello, I am trying to make a simple program that I made to test around with in Windows Forms. I am programming in Visual Basic and I am trying to resize the border of the program. Is this possible? Thanks!

dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
1 Vote"
Viorel-1 answered Viorel-1 edited

Try adding this Sub to your form class:

 Protected Overrides Sub WndProc(ByRef m As Message)
    
     Const WM_NCHITTEST = &H84
     Const HTCAPTION = 2
     Const HTLEFT = 10
     Const HTRIGHT = 11
     Const HTTOP = 12
     Const HTBOTTOM = 15
    
     Select Case m.Msg
         Case WM_NCHITTEST
             Dim p = New Point(m.LParam.ToInt32)
             Dim r = Me.Bounds
             Dim b = New Size(10, 10) ' or SystemInformation.FrameBorderSize '
    
             If p.X <= r.Left + b.Width Then
                 m.Result = New IntPtr(HTLEFT)
             ElseIf p.X >= r.Right - b.Width Then
                 m.Result = New IntPtr(HTRIGHT)
             ElseIf p.Y <= r.Top + b.Height Then
                 m.Result = New IntPtr(HTTOP)
             ElseIf p.Y >= r.Bottom - b.Height Then
                 m.Result = New IntPtr(HTBOTTOM)
             Else
                 m.Result = New IntPtr(HTCAPTION)
             End If
         Case Else
             MyBase.WndProc(m)
     End Select
    
 End Sub

You can improve it to allow diagonal resizing.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.