Pacific Database

Home | Contact | FAQs | View Cart

A world of information at your fingertips

Forms :: Sizegrip

How to add a working sizegrip to a form without subclassing

This one is so easy. Just add a Label, called lblGrip, to a form, and set it's properties as follows:

  • Height: 0.49cm
  • Width: 0.49cm
  • Caption = "o"
  • Font Name: Marlett
  • Font Size: 12

Place the Label so its bottom-right corner lies at the extreme bottom-right corner of the form.

Add the following code to a standard module.

'Declarations section
Public Declare Function ReleaseCapture Lib "user32" () As Long
Public Declare Function SendMessage Lib "user32" Alias _
    "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _
    Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_NCLBUTTONDOWN = &HA1
Public Const HTBOTTOMRIGHT = 17

Add the following code to the form.

Private Sub lblGrip_MouseDown(Button As Integer, _
	Shift As Integer, X As Single, Y As Single)
'*****************************************
' Original code by Karl E. Peterson MVP
' http://vb.mvps.org/articles/ap199906.pdf
'*****************************************
    'Negate VB's call to SetCapture, and tell Windows that the user is trying
    'to resize the form.
    ReleaseCapture
    SendMessage hwnd, WM_NCLBUTTONDOWN, HTBOTTOMRIGHT, ByVal 0&
    Call SetCustomCursor(, csrSIZENWSE)
End Sub
Private Sub lblGrip_MouseMove(Button As Integer, _
	Shift As Integer, X As Single, Y As Single)
    Call SetCustomCursor(, csrSIZENWSE)
End Sub
Private Sub Form_Resize()
    On Error GoTo Proc_Err
    
    Me.Width = Me.InsideWidth
    Me.Section(acDetail).Height = Me.InsideHeight
    
    Me.ChildForm.Move Me.ChildForm.left, _
                      Me.ChildForm.top, _
                      Me.InsideWidth - (Me.ChildForm.left * 2), _
                      Me.InsideHeight - (Me.ChildForm.top * 2)
    
    Me.lblGrip.Move Me.InsideWidth - Me.lblGrip.Width - 7, _
                    Me.InsideHeight - Me.lblGrip.Height - 7
    
    Call SetCustomCursor(, csrSIZENWSE)
    
Proc_Err:
End Sub