how do you make sure that when you maximise a form in vb, the controls in it are also maximised. Thanks for the help.

Recommended Answers

All 2 Replies

Try the following for the controls -

Private Sub Form_Resize()
    With Frame1
        .Left = 0
        .Top = 0
        .Width = Me.ScaleWidth
        .Height = Me.ScaleHeight
    End With
    With Text1
        .Top = Frame1.Top + 200
        .Left = Frame1.Left + 100
        .Width = Frame1.Width - 200
        .Height = Frame1.Height - 300
    End With
End Sub

You can also try the following which returns the size as the user increases the size of the form.

'In a module add the following code
Option Explicit

Public defWindowProc As Long
Private Const GWL_WNDPROC As Long = (-4)
Private Const WM_DESTROY = &H2
Private Const WM_SIZING = &H214

'wParam for WM_SIZING message
Private Const WMSZ_LEFT = 1
Private Const WMSZ_RIGHT = 2
Private Const WMSZ_TOP = 3
Private Const WMSZ_TOPLEFT = 4
Private Const WMSZ_TOPRIGHT = 5
Private Const WMSZ_BOTTOM = 6
Private Const WMSZ_BOTTOMLEFT = 7
Private Const WMSZ_BOTTOMRIGHT = 8

Private Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Private Declare Function GetWindowLong Lib "user32" _
    Alias "GetWindowLongA" _
   (ByVal hwnd As Long, _
    ByVal nIndex As Long) As Long
    
Private Declare Function SetWindowLong Lib "user32" _
    Alias "SetWindowLongA" _
   (ByVal hwnd As Long, _
    ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long
   
Private Declare Function CallWindowProc Lib "user32" _
    Alias "CallWindowProcA" _
   (ByVal lpPrevWndFunc As Long, _
    ByVal hwnd As Long, _
    ByVal uMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" _
   Alias "RtlMoveMemory" _
   (hpvDest As Any, _
    hpvSource As Any, _
    ByVal cbCopy As Long)



Public Sub Unhook(fhwnd As Long)
    
   If defWindowProc Then
      Call SetWindowLong(fhwnd, GWL_WNDPROC, defWindowProc)
      defWindowProc = 0
   End If

End Sub


Public Sub Hook(fhwnd As Long)
    
   defWindowProc = SetWindowLong(fhwnd, _
                                 GWL_WNDPROC, _
                                 AddressOf WindowProc)
                                  
   
End Sub


Function WindowProc(ByVal hwnd As Long, _
                    ByVal uMsg As Long, _
                    ByVal wParam As Long, _
                    ByVal lParam As Long) As Long

   Dim rc As RECT
   
   Select Case uMsg
   
      Case WM_SIZING
      
        'copy the RECT pointed to in
        'lParam into a RECT structure
         CopyMemory rc, ByVal lParam, LenB(rc)
      
        'wParam tells which one of the eight
        'possible resizing handles is being used.
        'Set the appropriate RECT member to the
        'size required to maintain aspect ratio,
        'and copy back into the RECT struct for
        'processing by Windows.
         Select Case wParam
         
            Case WMSZ_LEFT
               rc.Bottom = (rc.Right - rc.Left) + rc.Top
               CopyMemory ByVal lParam, rc, LenB(rc)
               WindowProc = 1
   
            Case WMSZ_RIGHT
               rc.Bottom = (rc.Right - rc.Left) + rc.Top
               CopyMemory ByVal lParam, rc, LenB(rc)
               WindowProc = 1
   
            Case WMSZ_TOP
               rc.Right = (rc.Bottom - rc.Top) + rc.Left
               CopyMemory ByVal lParam, rc, LenB(rc)
               WindowProc = 1
   
            Case WMSZ_BOTTOM
               rc.Right = (rc.Bottom - rc.Top) + rc.Left
               CopyMemory ByVal lParam, rc, LenB(rc)
               WindowProc = 1
   
            Case WMSZ_TOPLEFT
               rc.Left = (rc.Top - rc.Bottom) + (rc.Right)
               CopyMemory ByVal lParam, rc, LenB(rc)
               WindowProc = 1
               
            Case WMSZ_TOPRIGHT
               rc.Right = (rc.Bottom - rc.Top) + rc.Left
               CopyMemory ByVal lParam, rc, LenB(rc)
               WindowProc = 1
   
            Case WMSZ_BOTTOMLEFT
               rc.Bottom = (rc.Right - rc.Left) + (rc.Top)
               CopyMemory ByVal lParam, rc, LenB(rc)
               WindowProc = 1
               
            Case WMSZ_BOTTOMRIGHT
               rc.Bottom = (rc.Right - rc.Left) + rc.Top
               CopyMemory ByVal lParam, rc, LenB(rc)
               WindowProc = 1
   
            End Select
      
         Case WM_DESTROY:
           'kill subclassing if active
            If defWindowProc <> 0 Then
               Call Unhook(Form1.hwnd)
            End If
      
    End Select
    
  'process windows messages
   WindowProc = CallWindowProc(defWindowProc, _
                               hwnd, _
                               uMsg, _
                               wParam, _
                               lParam)

End Function

'In your form, add a command button and the following code.
Option Explicit

Private Sub Form_Load()

   With Form1
      
      .Width = 6000
      .Height = 6000
      Call Hook(.hwnd)
   
   End With
   
End Sub


Private Sub Command1_Click()

   Unload Me
   
End Sub


Private Sub Form_Unload(Cancel As Integer)

    Call Unhook(Me.hwnd)

End Sub

if I not understand wrong then plz try it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.