Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adjusting to user's screen resolution..
Message
From
18/10/2006 06:44:21
 
 
To
17/10/2006 22:13:16
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
01162801
Message ID:
01162849
Views:
68
This message has been marked as the solution to the initial question of the thread.
Some websites however have some script to automatically adjust to user's screen resolution.

Do we have something like this in VFP?


It is best not to mess with the user's screen resolution. It is better to adjust your form's based on what the resolution is. In VFP 9, you can use anchors to do this. However, I have this form class that I developed in VFP 3 that automatically resizes the forms to fill the user's screen at the resoltion he is using:
DEFINE CLASS frmmaximize AS FORM


  DOCREATE = .T.
  widthratio = 0
  heightratio = 0
  NAME = "frmmaximize"


  *-- Drill down into pageframes, pages, grids, etc on the form and resize all of the controls
  PROCEDURE resizecontrols
    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
  ENDPROC


ENDDEFINE
Previous
Reply
Map
View

Click here to load this message in the networking platform