Advertisement
5_2007-2008 Miscellaneous #182284

Auto resize that works

I needed a *good* auto resizer to minimize the time spent on resize code. I tried a few auto resizers, but none of them worked the way I wanted. So, I threw together this little piece of code. Unlike other resizers making assumptions on how to resize your controls, this code makes no assumptions. You the programmer are in total control of the resize behavior of each control on the form. IMPORTANT NOTES BELOW!

AI

Resumen de IA: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Código fuente
original-source
'*** put the following code in a module or something normal
Public Sub ResizeOMatic(frm As Form, adj() As CtlAdj)
  '** ResizeOMatic :: this sub moves and resizes controls on the form based
  '** on the adjustment data passed. Each element of the adj array should be
  '** in sequence as long as VB enumerates the controls in the same order as it
  '** did when the adj array was built (sub RegisterForm)
  
  Dim tmpControl As Control
  Dim index As Long
  
  On Error Resume Next        'keepin it real
      
  index = 0
  For Each tmpControl In frm
    index = index + 1
    
    Select Case LCase$(tmpControl.Tag)
      
      Case "rx"      'relative X
        tmpControl.Left = frm.width - tmpControl.width - adj(index).adjX
      
      Case "ry"      'relative Y
        tmpControl.Top = frm.height - tmpControl.height - adj(index).adjY
         
      Case "rxy"     'relative XY
        tmpControl.Left = frm.width - tmpControl.width - adj(index).adjX
        tmpControl.Top = frm.height - tmpControl.height - adj(index).adjY
        
      Case "sx"      'stretch X
        tmpControl.width = frm.width - tmpControl.Left - adj(index).adjX
        
      Case "sy"      'stretch Y
        tmpControl.height = frm.height - tmpControl.Top - adj(index).adjY
        
      Case "sxy"     'stretch XY
        tmpControl.width = frm.width - tmpControl.Left - adj(index).adjX
        tmpControl.height = frm.height - tmpControl.Top - adj(index).adjY
        
    End Select
  
  Next
  
End Sub

Public Sub RegisterForm(frm As Form, width As Long, height As Long, adj() As CtlAdj)
  '** RegisterForm :: this sub enumerates the controls on the form and records
  '** the positions of the bottom right corner of the control. We have to pass the
  '** width and height parameters (initial point of reference) because MDI
  '** automagically sizes forms. The adjustment data is used in Sub ResizeOMatic
    
  Dim tmpControl As Control
  
  ReDim adj(0)
  On Error Resume Next                 'keepin it real
  
  For Each tmpControl In frm
    ReDim Preserve adj(UBound(adj) + 1)
    adj(UBound(adj)).adjX = width - (tmpControl.Left + tmpControl.width)
    adj(UBound(adj)).adjY = height - (tmpControl.Top + tmpControl.height)
  Next
 
End Sub
'*********** The following code is a form
'*********** demonstrating how to use it
Private Sizedata() As CtlAdj
Private Sub Form_Load()
  
  '** load your stuff here
  
  'call this near the end of the form_load()
'Note: On MDI child forms, you should manually
'specify the width and height to your design time
'size to keep proper proportions
  RegisterForm Me, Me.Width, Me.Height, Sizedata()
  
End Sub
Private Sub Form_Resize()
  
  ResizeOMatic Me, Sizedata()
  
End Sub
Comentarios originales (3)
Recuperado de Wayback Machine