Results 1 to 4 of 4

Thread: Resizing Forms

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    Keniltworth, Cape Town, Western Province, South Africa
    Posts
    2

    Question Resizing Forms

    I am presently busy developing an application. I want to know the code that will enable me to resize forms that have controls on them?

  2. #2
    Addicted Member
    Join Date
    May 2001
    Posts
    153

    Unhappy Re: Resizing Forms

    Hi,

    YOu need to use Scalewidth and scaleheight properties of the form
    to position the controls or resize the controls.

    Venkrishna.

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'Resize your form base on screen resolution. 
    
    Option Explicit 
    
    Private lngFormWidth As Long 
    Private lngFormHeight As Long 
    
    Private Sub Form_Load() 
    
    Dim Ctl As Control 
    
    'Store form dimensions in variables 
    
    lngFormWidth = ScaleWidth 
    lngFormHeight = ScaleHeight 
    
    'Store initial control dimensions 
    'in the Tag property - with error 
    'handling for those controls which 
    'do not have properties such as Top 
    '(eg, Line control) 
    
    On Error Resume Next 
    
    For Each Ctl In Me 
    Ctl.Tag = Ctl.Left & " " & Ctl.Top & " " & _ 
    Ctl.Width & " " & Ctl.Height & " " 
    Ctl.Tag = Ctl.Tag & Ctl.FontSize & " " 
    Next Ctl 
    
    On Error GoTo 0 
    
    End Sub 
    
    Private Sub Form_Resize() 
    
    Dim D(4) As Double 
    Dim i As Long 
    
    Dim TempPoz As Long 
    Dim StartPoz As Long 
    
    Dim Ctl As Control 
    Dim TempVisible As Boolean 
    
    Dim ScaleX As Double 
    Dim ScaleY As Double 
    
    'Calculate the scale 
    
    ScaleX = ScaleWidth / lngFormWidth 
    ScaleY = ScaleHeight / lngFormHeight 
    
    On Error Resume Next 
    
    'Cycle through each control 
    
    For Each Ctl In Me 
    TempVisible = Ctl.Visible 
    Ctl.Visible = False 
    StartPoz = 1 
    
    'Read data from the Tag property 
    
    For i = 0 To 4 
    TempPoz = InStr(StartPoz, Ctl.Tag, " ", _ 
    vbTextCompare) 
    
    If TempPoz > 0 Then 
    D(i) = Mid(Ctl.Tag, StartPoz, _ 
    TempPoz - StartPoz) 
    StartPoz = TempPoz + 1 
    Else 
    D(i) = 0 
    End If 
    
    'Move the control based on data 
    'in the Tag property and the form 
    'scale... 
    
    Ctl.Move D(0) * ScaleX, D(1) * ScaleY, _ 
    D(2) * ScaleX, D(3) * ScaleY 
    Ctl.Width = D(2) * ScaleX 
    Ctl.Height = D(3) * ScaleY 
    
    'Change font size 
    
    If ScaleX < ScaleY Then 
    Ctl.FontSize = D(4) * ScaleX 
    Else 
    Ctl.FontSize = D(4) * ScaleY 
    End If 
    
    Next i 
    
    Ctl.Visible = TempVisible 
    
    Next Ctl 
    
    On Error GoTo 0 
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Addicted Member Sanj's Avatar
    Join Date
    Apr 2001
    Location
    in front of my PC
    Posts
    242
    hi

    do u mean that on ur form u have lots of other objkects like grids, frames... and when u resize ur form u want the rest to resize with it??

    if thats the case then this is the code i religiously use and its great!!

    just tweak it for ur objects!

    Code:
    Private Sub Form_Resize()
       
        If frmMain.WindowState <> 1 Then
            ' Resize the rtbTerm (display) control
            rtbTerm.Move 50, tbrToolBar.Height + 100, ((frmMain.ScaleWidth) / 2) - 50, frmMain.ScaleHeight - sbrStatus.Height - tbrToolBar.Height - 100
            
            'Position and Resize frameSpecial_Keys
            FrameSpecial_Keys.Move ((frmMain.ScaleWidth) / 2) + 50, tbrToolBar.Height + 3505, 1575, 855
            
            'Position the Grid
            gridExtracted_Information_Grid.Move ((frmMain.ScaleWidth) / 2), tbrToolBar.Height + 100, ((frmMain.ScaleWidth) / 2) - 100, ((frmMain.ScaleHeight - sbrStatus.Height - tbrToolBar.Height) / 2) - 100
             
        End If
    Sanj

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