Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sizing and centering for multiple screen resolutions
Message
De
05/08/2004 12:40:01
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00930975
Message ID:
00931075
Vues:
26
Hi Rudy.

I guess I could have made it clearer. I want the form to cover the entire view of the screen. I want commands etc. that are centered to be centered on all monitors. I want commands etc. that are near the top to be near the top, near the bottom, near the bottom etc.

If you have a copy of 1001 Things You Wanted to Know About Visual FoxPro, we have a form class in Chapter 11 that does exactly what you are looking for:

How do I make my forms fill the entire screen regardless of the screen resolution? (Example: CH11.VCX::FrmMaximize and Maximize.scx)

If the application you are building is sovereign, (i.e. an application intended to be used exclusively by a user, as opposed to merely sharing a portion of the user's screen with other applications) you will probably want the forms to maximize themselves when instantiated, regardless of the screen resolution a particular user has set.
To do this you will need to calculate the ratio by which the current screen resolution differs from the standard (which should always be 640 x 480 anyway!) for which your forms are designed. This ratio can then be applied to all forms and their controls to resize everything without changing relative proportions. This is best accomplished by adding a ResizeControls method to the form class and calling it from the form's Init method, after first re-sizing the form itself, like so:
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	
Note that we are using the native SysMetric() function to determine the current screen resolution and then calculate both the horizontal and vertical ratios. These ratios are saved as form properties and used immediately to re-size the form itself. We then loop through each of the object in the form's Controls collection, calling the ResizeControls method, and passing an object reference to the control for each one.

The ResizeControls method must take different action depending on whether the object that it receives is a simple control or another container with more controls. To handle this situation the method has to be able to drill down into containers by calling itself recursively. The first task, however, is to set the Top, Left, Height and Width properties for the passed control if it has these properties. (Your first thought may well be that surely all visual controls have these properties? Not so, Pageframes, for example, do not actually have Height and Width, instead they have PageHeight and PageWidth properties.)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform