Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anyone have "re-size" code

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
Does anyone have some standard code for resizing forms ?
 
I have one I use to resize my child forms in the MDIForm when the MDI form is resized. Is that what you are looking for? If so, try this in your MDI form code:

Option Explicit
Dim load as Boolean

Private Sub Form_Load()
load = true 'this must be first line in form_load sub
End Sub

Private Sub Form_Resize()
Dim mdiForm as Form

With Me.ActiveForm
If (load = False) Then
.width = MDIForm1.ScaleWidth
.Height = MDIForm1.ScaleHeight
End If
End With
load = false
End Sub
Best Regards and many Thanks!
Michael G. Bronner X-)

"Beer is proof that God wants us to be happy." Ben Franklin
 
Resizes controls and form
Code:
    objgControls.DesignWidth = 11940 ' ScaleWidth (Twips) of frmHome
    objgControls.DesignHeight = 8175 ' ScaleHeight (Twips) of frmHome
    objgControls.NowWidth = Me.ScaleWidth
    objgControls.NowHeight = Me.ScaleHeight
    objgControls.FormResizer Me
'====
'.BAS or .CLS module objgControls
Public DesignWidth  As Double   ' Form width at design time
Public DesignHeight As Double   ' Form height at desin time
Public NowWidth     As Double
Public NowHeight    As Double
Public Sub FormResizer(frmW As Form)
    Dim ctlW            As Control, _
        vW              As Double, _
        vH              As Double, _
        strName         As String, _
        blnWindowState  As Boolean
    Dim strDescription As String
        
    strName = frmW.Name
    
    If objgControls.IsTag(frmW, "RESIZED=YES") Then Exit Sub
    
    frmW.Tag = objgFmt.AddKeyword(frmW.Tag, "RESIZED=YES")
    
    If DesignWidth = 0 Or DesignHeight = 0 Then Exit Sub
    
    vW = NowWidth / DesignWidth
    vH = NowHeight / DesignHeight
    If vW > 0.95 And vW < 1.05 And _
       vH > 0.95 And vH < 1.05 Then
       Exit Sub
    End If
            
    With frmW
        On Error Resume Next
            If frmW.WindowState <> vbMaximized Then
                .Width = .Width * vW
                .Height = .Height * vH
                .Left = (NowWidth - .Width) / 2
                .Top = (NowHeight - .Height) / 2
            End If
        On Error GoTo 0
    End With
    
    For Each ctlW In frmW.Controls
        With ctlW
            On Error Resume Next
                strName = UCase$(.Name)
                'Debug.Assert (strName <> &quot;GRDATE&quot;)
                .Font.Size = (.Font.Size * vH) \ 1
                strDescription = Err.Description
            On Error GoTo 0
            On Error Resume Next
                .Move .Left * vW, .Top * vH, .Width * vW, .Height * vH
                If Err Then
                    .Left = .Left * vW
                    .Top = .Top * vH
                    .Width = .Width * vW
                    .Height = .Height * vH
                End If
                strDescription = Err.Description
            On Error GoTo 0
        End With
    Next

End Sub
 
What s the exact function of NowWidth? Why not use just Width?

Thanks :) Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;Beer is proof that God wants us to be happy.&quot; Ben Franklin
 
First of all you would want ScaleWidth not Width. I resize based on the ScaleWidth/Height in Twips of a known form whose scale is in Twips so I want separate variables for this. Feel free to change whatever you like to whatever works for you. This works for me with maximized MDI forms.

 
John,
I used ScaleWidth as well. But I was referring to your using .NowWidth. How was that different than just using .Widht? Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;Beer is proof that God wants us to be happy.&quot; Ben Franklin
 
Code:
' One-time setting of Design and NOW (Run-time) Scale Dimensions from a known maximized MDI form.
objgControls.DesignWidth = 11940 ' ScaleWidth (Twips) of frmHome
    objgControls.DesignHeight = 8175 ' ScaleHeight (Twips) of frmHome
    objgControls.NowWidth = Me.ScaleWidth
    objgControls.NowHeight = Me.ScaleHeight
[/code
Perhaps if I renamed it NOWScaleWidth.
 [URL unfurl="true"]WWW.VBCompare.Com[/URL]
 
Ok, I got it! Thanks. :) Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;Beer is proof that God wants us to be happy.&quot; Ben Franklin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top