- Why is the minimum size of a top-level window constrained to 2x2 pixels?
- Is it possible to override this constraint so that I
The minimum size of a window is normally restricted to the smallest size that still allows the system menu and the caption buttons to be accessible by the user. Even for borderless windows, not exactly appropriate. You can make it smaller by explicitly setting the Size property after the window is created, normally the Load event handler is your first opportunity. Or OnHandleCreated().
But yeah, Windows still restricts it to 2x2, the "why" is elusive. Surely what you really want to know is how to work around it. You do so by intercepting the WM_GETMINMAXINFO message and lowering the minimum track size. A sample form class that demonstrates the approach:
Imports System.Runtime.InteropServices
Public Class Form1
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
If m.Msg = WM_GETMINMAXINFO Then
Dim mmi = DirectCast(Marshal.PtrToStructure(m.LParam, GetType(MINMAXINFO)), MINMAXINFO)
mmi.ptMinTrackSize = New Point(0, 0)
Marshal.StructureToPtr(mmi, m.LParam, False)
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Size = New Size(0, 0)
MsgBox(Me.Size.ToString())
End Sub
Private Const WM_GETMINMAXINFO As Integer = &h24
Private Structure MINMAXINFO
Public ptReserved As Point
Public ptMaxSize As Point
Public ptMaxPosition As Point
Public ptMinTrackSize As Point
Public ptMaxTrackSize As Point
End Structure
End Class
Tested on Windows 8.1. I can't promise that it will work on all Windows versions. It should.