I'm working on a VB.Net windows form application where we needed a custom title bar, so we removed the default title bar from our form (by setting FormBorderStyle to None). After doing this, I found that resizing the form was not allowed.
Based on some research, I implemented the following code:
Code:
Protected Overrides Sub WndProc(ByRef m As Message)
Const RESIZE_HANDLE_SIZE As Integer = 10
Select Case m.Msg
Case &H84
MyBase.WndProc(m)
'rsd 21.07.23 (1) s
'Resize not allowed for embedded exe
If IsEmbeddedExe() Then Exit Sub
'rsd 21.07.23 (1)
If CInt(m.Result) = &H1 Then
Dim screenPoint As Point = New Point(m.LParam.ToInt32())
Dim clientPoint As Point = Me.PointToClient(screenPoint)
If clientPoint.Y <= RESIZE_HANDLE_SIZE Then
If clientPoint.X <= RESIZE_HANDLE_SIZE Then
m.Result = CType(13, IntPtr)
ElseIf clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE) Then
m.Result = CType(12, IntPtr)
Else
m.Result = CType(14, IntPtr)
End If
ElseIf clientPoint.Y <= (Size.Height - RESIZE_HANDLE_SIZE) Then
If clientPoint.X <= RESIZE_HANDLE_SIZE Then
m.Result = CType(10, IntPtr)
ElseIf clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE) Then
m.Result = CType(2, IntPtr)
Else
m.Result = CType(11, IntPtr)
End If
Else
If clientPoint.X <= RESIZE_HANDLE_SIZE Then
m.Result = CType(16, IntPtr)
ElseIf clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE) Then
m.Result = CType(15, IntPtr)
Else
m.Result = CType(17, IntPtr)
End If
End If
End If
Return
End Select
MyBase.WndProc(m)
End Sub
This solved the resizing issue, but now windows+D and windows+M shortcuts were not working.
Using below code windows+D and windows+M shortcuts were working, but resizing issue reappeared.
Code:
Private Const WS_SYSMENU As Integer = &H80000
Private Const WS_MINIMIZEBOX As Integer = &H20000
Protected Overrides ReadOnly Property CreateParams As CreateParams
Get
Dim p As CreateParams = MyBase.CreateParams
'here the window has a system menu and a minimize button. It checks if these styles are already present If not, it adds them to the window style.
p.Style = p.Style Or WS_SYSMENU Or WS_MINIMIZEBOX
Return p
End Get
End Property
My Requirements:
1. The Window+D and Window+M shortcuts should work.
2. The form should be resizable.
I also found out from the Microsoft official site that when Window+D is pressed, no message is received by the application, and everything is handled by the OS.How can I enable Window+D and Window+M shortcuts in my VB.Net form while also allowing the form to be resizable? Any help or guidance would be greatly appreciated!