Results 1 to 32 of 32

Thread: Control Resize Code

Threaded View

  1. #1

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Control Resize Code

    The following code will reposition and resize almost all controls on a form. Any comments and/or suggestions on improving this code will be greatly appreciated:

    VB Code:
    1. Option Explicit
    2. Dim sngFrmTop As Single
    3. Dim sngFrmLeft As Single
    4. Dim sngFrmHeight As Single
    5. Dim sngFrmWidth As Single
    6.  
    7. Dim sngCntTop() As Single
    8. Dim sngCntLeft() As Single
    9. Dim sngCntHeight() As Single
    10. Dim sngCntWidth() As Single
    11. Dim sngCntFont() As Single
    12.  
    13. Private Sub Form_Load()
    14. Dim a As Long
    15.    
    16.    On Error GoTo Form_Load_Error
    17.  
    18.     sngFrmTop = Top
    19.     sngFrmLeft = Left
    20.     sngFrmHeight = Height
    21.     sngFrmWidth = Width
    22.    
    23.     ReDim sngCntTop(Controls.Count)
    24.     ReDim sngCntLeft(Controls.Count)
    25.     ReDim sngCntHeight(Controls.Count)
    26.     ReDim sngCntWidth(Controls.Count)
    27.     ReDim sngCntFont(Controls.Count)
    28.    
    29.     For a = 0 To Controls.Count - 1
    30.         With Me.Controls(a)
    31.             sngCntTop(a) = (.Top / sngFrmHeight)
    32.             sngCntLeft(a) = (.Left / sngFrmWidth)
    33.             sngCntHeight(a) = (.Height / sngFrmHeight)
    34.             sngCntWidth(a) = (.Width / sngFrmWidth)
    35.             sngCntFont(a) = (.FontSize / sngFrmHeight)
    36.         End With
    37.     Next a
    38.  
    39.    On Error GoTo 0
    40.    Exit Sub
    41.  
    42. Form_Load_Error:
    43. If Err.Number = 13 Then
    44.     Resume Next
    45. Else
    46.     MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Form_Load of Form Form1"
    47. End If
    48. End Sub
    49.  
    50. Private Sub Form_Resize()
    51. Dim a As Long
    52.    
    53.    On Error GoTo Form_Resize_Error
    54.  
    55.     sngFrmTop = Top
    56.     sngFrmLeft = Left
    57.     sngFrmHeight = Height
    58.     sngFrmWidth = Width
    59.    
    60.     For a = 0 To Me.Controls.Count - 1
    61.         With Me.Controls(a)
    62.             .Top = sngFrmHeight * sngCntTop(a)
    63.             .Left = sngFrmWidth * sngCntLeft(a)
    64.             .Height = sngFrmHeight * sngCntHeight(a)
    65.             .Width = sngFrmWidth * sngCntWidth(a)
    66.             .FontSize = Int(sngFrmHeight * sngCntFont(a))
    67.         End With
    68.     Next a
    69.  
    70.    On Error GoTo 0
    71.    Exit Sub
    72.  
    73. Form_Resize_Error:
    74. If Err.Number = 383 Then 'Catch Error for controls with read only properties
    75.     Resume Next
    76. Else
    77.     MsgBox "Error " & Err.Number & " (" & Err.Description & _
    78.             ") in procedure Form_Resize of Form Form1"
    79. End If
    80. End Sub
    Last edited by Mark Gambo; Dec 15th, 2005 at 05:14 PM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width