Maximize A Form To Cover All The Screen

Maximize a form to cover the whole screen, including the task bar.

Preparations

Add 2 Command Buttons to your form. Press the first to cover the whole screen, and the second for regular maximizing.

Module Code

Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
        ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
        ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  
Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
  
Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1
Public Const HWND_TOP = 0
Public Const SWP_SHOWWINDOW = &H40

Form Code

Private Sub Command1_Click()
    Dim ll_Width As Long
    Dim ll_Height As Long
   
    If Me.WindowState = vbMaximized Then
        WindowState = vbNormal
    End If
  
    'work out full screen dimensions
    ll_Width = GetSystemMetrics(SM_CXSCREEN)
    ll_Height = GetSystemMetrics(SM_CYSCREEN)
  
    'use SetWindowPos to resize window
    Call SetWindowPos(Me.hwnd, HWND_TOP, 0, 0, ll_Width, _
        ll_Height, SWP_SHOWWINDOW)
End Sub
     
Private Sub Command2_Click()
    WindowState = vbMaximized
End Sub


Go Back