Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Autosizing to auto fit to a user's screen setting
Message
From
11/09/2006 06:52:55
 
 
To
10/09/2006 13:08:39
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01152656
Message ID:
01152720
Views:
19
Is there a nice easy bit of code that will detect a user's screen setting (800x600) or (1024x768) etcetera and adjust a fox executable to fit the user's screen settings?

This code in the init() of your 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
And this code in the ResizControls() method:
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, unless it is a grid or editbox
*** in which case we want to see more info
IF NOT INLIST( UPPER( ALLTRIM( toControl.BASECLASS ) ), 'GRID', 'EDITBOX' )
  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
      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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform