Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Forms and screen resolution
Message
 
To
25/04/2009 08:02:57
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
01396126
Message ID:
01397035
Views:
96
Marcia, a quest if I may about this resizing solution. It worked for 1 form but my other form which has alot of textboxes on it, many of the textboxes are off the screen now. Would this be possible if I didn't err somewhere?

>
>You create a form class using the form designer and name the class frmMaximize
>
>You then add 2 custom properties:
>
>WidthRatio
>HeightRatio
>
>and set them to 0
>
>Add this code to the Init() of the form class:
>
>
>     Local loControl
>     With Thisform
>      *** Determine the ratio needed to maximize the form
>      *** depending on screen resolution and store it to form properties
>      .widthratio = Sysmetric( 1 ) / 640
>      .heightratio = Sysmetric( 2 ) / 480
>      *** If resolution is higher than 640 x 480, reposition
>      *** and maximize the form
>      If .widthratio > 1
>        .Top = 0
>        .Left = 0
>        .Width = .Width * .widthratio
>        .Height = .Height * .heightratio
>        *** And resize each control contained in the form
>        For Each loControl In .Controls
>          .resizecontrols( loControl )
>        Endfor
>      Endif
>    Endwith
>
>
>Add a custom method called ResizeControls to your form class and put the code below into it
>
>>>
>>>    Lparameters toControl
>>>    Local loPage, loControl, loColumn, lnColumnWidths[1], lnCol
>>>
>>>    If Pemstatus( toControl, 'Width', 5 )
>>>      toControl.Width = toControl.Width * Thisform.widthratio
>>>    Endif
>>>    If Pemstatus( toControl, 'Height', 5 )
>>>      toControl.Height = toControl.Height * Thisform.heightratio
>>>    Endif
>>>    If Pemstatus( toControl, 'Top', 5 )
>>>      toControl.Top = toControl.Top * Thisform.heightratio
>>>    Endif
>>>    If Pemstatus( toControl, 'Left', 5 )
>>>      toControl.Left = toControl.Left * Thisform.heightratio
>>>    Endif
>>>    *** Now resize the font of the control, grid (naturally <g>) is a special case because
>>>    *** resizing the font resizes the column widths of the grid, so save and restore them
>>>    If Upper( Alltrim( toControl.BaseClass ) ) = 'GRID'
>>>      Dimension lnColumnWidths[toControl.ColumnCount]
>>>      For lnCol = 1 To toControl.ColumnCount
>>>        lnColumnWidths[lnCol] = toControl.Columns[lnCol].Width
>>>      Endfor
>>>      toControl.FontSize = Int( toControl.FontSize * Thisform.widthratio )
>>>      For lnCol = 1 To toControl.ColumnCount
>>>        toControl.Columns[lnCol].Width = lnColumnWidths[lnCol]
>>>      Endfor
>>>    Else
>>>      If Pemstatus( toControl, 'Fontsize', 5 )
>>>        toControl.FontSize = Int( toControl.FontSize * Thisform.widthratio )
>>>      Endif
>>>    Endif
>>>    Do Case
>>>      Case Upper( toControl.BaseClass ) = 'PAGEFRAME'
>>>        For Each loPage In toControl.Pages
>>>          Thisform.resizecontrols( loPage )
>>>        Endfor
>>>
>>>      Case Inlist( Upper( toControl.BaseClass ), 'PAGE', 'CONTAINER' )
>>>        For Each loControl In toControl.Controls
>>>          Thisform.resizecontrols( loControl )
>>>        Endfor
>>>
>>>      Case Upper( toControl.BaseClass ) = 'GRID'
>>>        With toControl
>>>          .RowHeight     = .RowHeight * Thisform.heightratio
>>>          .HeaderHeight  = .HeaderHeight * Thisform.heightratio
>>>          For Each loColumn In .Columns
>>>            loColumn.Width = loColumn.Width * Thisform.widthratio
>>>          Endfor
>>>        Endwith
>>>
>>>      Case Inlist( Upper( toControl.BaseClass ), 'COMBOBOX', 'LISTBOX' )
>>>        Local lnCol, lnStart, lnEnd, lnLen, lcColumnWidths
>>>        With toControl
>>>          If .ColumnCount < 2
>>>            .ColumnWidths = Alltrim( Str( .Width ) )
>>>          Else
>>>            lcColumnWidths = ''
>>>            lnStart = 1
>>>            For lnCol = 1 To .ColumnCount - 1
>>>              lnEnd = At( ',', .ColumnWidths, lnCol )
>>>              lnLen = lnEnd - lnStart
>>>              lcColumnWidths = lcColumnWidths + Iif( Empty( lcColumnWidths ), '', ',' ) + Alltrim( Str( Val (Substr( .ColumnWidths, lnStart, lnLen ) ) * Thisform.widthratio ) )
>>>              lnStart = lnEnd + 1
>>>            Endfor
>>>            lnLen = Len( .ColumnWidths ) - lnStart + 1
>>>            lcColumnWidths = lcColumnWidths + ',' + Alltrim( Str( Val (Substr( .ColumnWidths, lnStart, lnLen ) ) * Thisform.widthratio ) )
>>>            .ColumnWidths = lcColumnWidths
>>>          Endif
>>>        Endwith
>>>
>>>      Case Inlist( Upper( Alltrim( toControl.BaseClass ) ), 'COMMANDGROUP', 'OPTIONGROUP' )
>>>        Local lnButton
>>>        For lnButton = 1 To toControl.ButtonCount
>>>          Thisform.resizecontrols( toControl.Buttons[lnButton] )
>>>        Endfor
>>>
>>>      Otherwise
>>>        *** There is no otherwise...I think we got all cases
>>>    Endcase
>>>  Endproc
>>>
>>>
>>>  Procedure Init
>>>    Local loControl
>>>
>>>    With Thisform
>>>      *** Determine the ratio needed to maximize the form
>>>      *** depending on screen resolution and store it to form properties
>>>      .widthratio = Sysmetric( 1 ) / 640
>>>      .heightratio = Sysmetric( 2 ) / 480
>>>      *** If resolution is higher than 640 x 480, reposition
>>>      *** and maximize the form
>>>      If .widthratio > 1
>>>        .Top = 0
>>>        .Left = 0
>>>        .Width = .Width * .widthratio
>>>        .Height = .Height * .heightratio
>>>        *** And resize each control contained in the form
>>>        For Each loControl In .Controls
>>>          .resizecontrols( loControl )
>>>        Endfor
>>>      Endif
>>>    Endwith
>>>
"Build a man a fire, and he's warm for a day.
Set a man on fire, and he's warm for the rest of his life."
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform