Sample Resize function

Discussion in 'Code Samples & Tips' started by IansResearch, Feb 3, 2009.

  1. IansResearch

    IansResearch Member Licensed User

    ' This repositions the controls adjusting height and width to the ratio to which the form has been changed.
    ' Stores initial control settings in InitControls() array

    ' Sample code to resize screen controls ....
    '
    Sub Globals
    InitHeight = 0
    InitWidth = 0

    Dim Controls(0) ' Used by Change to VGA
    Dim Type(Left,Top,Width,Height) InitControls(0) ' Used by Landscape / Port

    End Sub

    Sub App_Start
    ' Set Initial form Height and Width ..
    InitHeight = Form1.Height
    InitWidth = Form1.Width


    frmLP.New1("Form1",B4PObject(1))


    If form1.Height > 400 Then ChangeToVGA

    Controls() = GetControls("") ' Get Controls Initial size and position
    n = ArrayLen(Controls())
    Dim InitControls(n,4)
    For i = 0 To ArrayLen(Controls())-1
    Select ControlType(Controls(i))
    Case "ListBox","NumUpDown","Button","TextBox","Label","ComboBox","Panel","RadioBtn","Table","ImageButton","CheckBox","Image"
    InitControls(i).Height = Control(Controls(i)).Height
    InitControls(i).Top = Control(Controls(i)).Top
    InitControls(i).Left = Control(Controls(i)).Left
    InitControls(i).Width = Control(Controls(i)).Width
    Case "TabControl.TabControl"
    InitControls(i).Height = Control(Controls(i),TabControl).Height
    InitControls(i).Top = Control(Controls(i),TabControl).Top
    InitControls(i).Left = Control(Controls(i),TabControl).Left
    InitControls(i).Width = Control(Controls(i),TabControl).Width
    Case "ProgressBar.ProgressBar"
    InitControls(i).Height = Control(Controls(i),ProgressBar).Height
    InitControls(i).Top = Control(Controls(i),ProgressBar).Top
    InitControls(i).Left = Control(Controls(i),ProgressBar).Left
    InitControls(i).Width = Control(Controls(i),ProgressBar).Width
    End Select
    Next

    frmLP_Resize

    Form1.Show

    End Sub

    Sub frmLP_Resize
    HeightRatio = form1.Height / (1.0 * InitHeight)
    WidthRatio = form1.Width / (1.0 * Initwidth)


    For i = 0 To ArrayLen(Controls())-1
    Select ControlType(Controls(i))
    Case "ListBox","NumUpDown","Button","TextBox","Label","ComboBox","Panel","RadioBtn","Table","ImageButton","CheckBox","Image"
    Control(Controls(i)).Left = WidthRatio * InitControls(i).Left
    Control(Controls(i)).Top = HeightRatio * InitControls(i).Top
    Control(Controls(i)).Height = HeightRatio * InitControls(i).Height
    Control(Controls(i)).Width = WidthRatio * InitControls(i).Width
    Case "TabControl.TabControl"
    Control(Controls(i),TabControl).Left = WidthRatio * InitControls(i).Left
    Control(Controls(i),TabControl).Top = HeightRatio * InitControls(i).Top
    Control(Controls(i),TabControl).Height = HeightRatio * InitControls(i).Height
    Control(Controls(i),TabControl).Width = WidthRatio * InitControls(i).Width
    Case "ProgressBar.ProgressBar"
    Control(Controls(i),ProgressBar).Left = WidthRatio * InitControls(i).Left
    Control(Controls(i),ProgressBar).Top = HeightRatio * InitControls(i).Top
    Control(Controls(i),ProgressBar).Height = HeightRatio * InitControls(i).Height
    Control(Controls(i),ProgressBar).Width = WidthRatio * InitControls(i).Width

    '*** Uncomment these lines if your application includes Tables.
    If ControlType(Controls(i)) = "Table" Then
    tbl = Controls(i)
    For i2 = 0 To Control(tbl,Table).ColCount-1
    col = Control(tbl,Table).ColName(i2)
    Control(tbl,Table).ColWidth(col) = Control(tbl,Table).ColWidth(col) * WidthRatio
    Next
    End If
    End Select
    Next

    End Sub

    ' ChangeToVGA - from Erell's Tutorial
    '
    Sub ChangeToVGA
    'Handles resolutions of 480 * 640
    Controls() = GetControls("")
    For i = 0 To ArrayLen(Controls())-1
    Select ControlType(Controls(i))
    Case "ListBox","NumUpDown","Button","TextBox","Label","ComboBox","Panel","RadioBtn","Table","ImageButton","CheckBox","Image"
    Control(Controls(i)).Left = 2 * Control(Controls(i)).Left
    Control(Controls(i)).Top = 2 * Control(Controls(i)).Top
    Control(Controls(i)).Height = 2 * Control(Controls(i)).Height
    Control(Controls(i)).Width = 2 * Control(Controls(i)).Width
    Case "TabControl.TabControl"
    Control(Controls(i),TabControl).Left = 2 * Control(Controls(i),TabControl).Left
    Control(Controls(i),TabControl).Top = 2 * Control(Controls(i),TabControl).Top
    Control(Controls(i),TabControl).Height = 2 * Control(Controls(i),TabControl).Height
    Control(Controls(i),TabControl).Width = 2 * Control(Controls(i),TabControl).Width
    '*** Uncomment these lines if your application includes Tables.
    If ControlType(Controls(i)) = "Table" Then
    tbl = Controls(i)
    For i2 = 0 To Control(tbl,Table).ColCount-1
    col = Control(tbl,Table).ColName(i2)
    Control(tbl,Table).ColWidth(col) = Control(tbl,Table).ColWidth(col) * 2
    Next
    End If
    End Select
    Next

    End Sub


    ' Hope this proves usefull does not include FONT rescaling...

    Ian :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice