Compensating for Different Screen Resolutions 
Author Message
 Compensating for Different Screen Resolutions


 I wish it where easier, but it is not.

Adjusting Form Size for Different Video Screen Resolutions
Article ID: Q103646

---------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual Basic programming system for Windows,
  versions 2.0 and 3.0
---------------------------------------------------------------------

SUMMARY
=======

Different display devices can have different resolutions (twips per pixel
ratios). These differences can cause form and control sizes and locations
to appear differently than when they were created. Two solutions to this
problem are:

 - Set the ScaleMode on all forms and picture boxes to Pixels (3). This
   unit of measurement does not depend on screen resolution, so forms and
   controls will always appear the same size and location relative to each
   other.

 - Adjust your form and control sizes and locations at run time to match
   visual elements which are not affected by the screen resolution. For
   example, the sample program given below adjusts the width of the client
   area of a form to match a bitmap which is a fixed number of pixels wide

   and is therefore not affected by screen resolution.

MORE INFORMATION
================

Step-by-Step Example
--------------------

1. Start Visual Basic or from the File menu, choose New Project (ALT, F,
N)
   if Visual Basic is already running. Form1 is created by default.

2. Add two labels, one command button, and one picture control to Form1.

3. Set Picture1's picture property to C:\WINDOWS\WINLOGO.BMP.

4. Add the following code in the Form Load event procedure of Form1:

   Sub Form_Load ()

      ' Set up a picture box:
      Picture1.AutoSize = True
      Picture1.Move 0, 0

      ' Set up the labels and command button:
      Xtwips& = Screen.TwipsPerPixelX
      Ytwips& = Screen.TwipsPerPixelY
      Ypixels& = Screen.Height / Ytwips&
      Xpixels& = Screen.Width / Xtwips&
      label1.Caption = "Below is resolution that you are running in"
      label2.Caption = Str$(Xpixels&) + " by " + Str$(Ypixels&)

      label1.Width = Picture1.Width
      label2.Width = Picture1.Width
      label1.Left = 0
      label2.Left = 0
      label1.Top = Picture1.Height + 10
      label2.Top = label1.Top + label1.Height + 10
      command1.Top = label2.Top + label2.Height + 10
      command1.Left = (Picture1.Width - command1.Width) / 2

      ' Size the form to fit the picture box, labels, and command button
      ScaleMode = 1  ' twips
      Width = Width - ScaleWidth + Picture1.Width

      ' Enter the Height statement as one, single line:
      Height = Height - ScaleHeight + Picture1.Height + label1.Height
         + label2.Height + command1.Height

   End Sub

5. Add the following code in the Command1 Click event procedure:

   Sub Command1_Click ()
      End
   End Sub

6. Press the F5 key to run the program. Click the Command1 button to exit
   from the example.

Additional reference words: 3.00
KBCategory: kbui kbprg kbcode
KBSubcategory: APrgWindow

Copyright 1993 Microsoft Corporation. All rights reserved.



Sun, 29 Mar 1998 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Compensating for different screen resolutions

2. Rezing Forms for Different Screen Resolutions

3. Dynamic GUI: Programming with VBA for different screen sizes and resolutions

4. Any technique to display window form in different screen resolution

5. dealing with different screen resolutions

6. Adapting To Different Screen Resolutions?

7. Handiling Different Screen Resolution

8. Forms in different screen resolutions

9. Adjusting VB for different screen resolutions

10. Different screen resolutions

11. Handiling Different Screen Resolution

12. Help! Compensate for video resolution

 

 
Powered by phpBB® Forum Software