Adjust forms to users' screen resolution 
Author Message
 Adjust forms to users' screen resolution

I developed a VB 4.0 program while my monitor's resoltion was 800 X 600.
One of my users complained he could not see some of the controls on
certain forms -  his monitor is set to 600 X 480. Is there any way for
the program to adjust to the resolution of the monitor?

I expected that setting a form's width and height properties to those of
the screen object would solve the problem but it does not. I could
redesign the forms while my monitor is at a  lower resolution, but I
hope to avoid doing that.



Wed, 22 Sep 1999 03:00:00 GMT  
 Adjust forms to users' screen resolution

 >I developed a VB 4.0 program while my monitor's resoltion was 800 X
600.
 >One of my users complained he could not see some of the controls on
 >certain forms -  his monitor is set to 600 X 480. Is there any way
for
 >the program to adjust to the resolution of the monitor?
 >
 >I expected that setting a form's width and height properties to
those of
 >the screen object would solve the problem but it does not. I could
 >redesign the forms while my monitor is at a  lower resolution, but I
 >hope to avoid doing that.
 >
The following code will save and recall the form size and position as
a fraction of the screen size.  So if you change screen resolutions,
the program will take up the same real-estate as it did before.

The defalt size is also a fraction.  So the window will be the same
size on everybodies screen the first time they run it.

If the user resizes the form, the lable sizes and positions will
automaticaly change to fit.

The new size and position will be remembered in the registry, when you
exit the program.
------------------------------------------

'Used to lock window updates until MyProg resize event is done.
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock
As Long) As Long

Private Sub Form_Load()
        'Get last position and size, as a fraction of the screen size.

        Form1.Top = GetSetting("MyProg", "Metrics", "Form1Top", ".1")
* Screen.Height
        Form1.Left = GetSetting("MyProg", "Metrics", "Form1Left",
".1") * Screen.Width
        Form1.Height = GetSetting("MyProg", "Metrics", "Form1Height",
".7") * Screen.Height
        Form1.Width = GetSetting("MyProg", "Metrics", "Form1Width",
".6") * Screen.Width
End Sub

Private Sub Form_Resize()
    'Lock all window updates
    zl& = LockWindowUpdate(Form1.hWnd)

    'Calculate font scale factor
    'Make sure all control fonts are TTF
    fx = 1 * Form1.ScaleWidth
    fy = 1 * Form1.ScaleHeight
    If fx > fy Then
        f = fy
    Else
        f = fx
    End If

    'This lable is a single line with autosize=True
    Label1.Font.Size = 0.008 * f
    Label2.Top = 0.1 * Form1.ScaleHeight
    Label1.Left = (Form1.ScaleWidth - Label1.Width) / 2

    'This lable is multiple lines with autosize=False
    Label2.Font.Size = 0.002 * f
    Label2.Top = 0.6 * Form1.ScaleHeight
    Label2.Height = 0.13 * f
    Label2.Width = 0.9 * f
    Label2.Left = (Form1.ScaleWidth - Label2.Width) / 2

    'Unlock window updates
    zl& = LockWindowUpdate(0)
End Sub

Private Sub mFileClose_Click()
'Menu item "&Close"
    'Save current position and size as a fraction of the screen size.
    SaveSetting "MyProg", "Metrics", "Form1Top", Form1.Top /
Screen.Height
    SaveSetting "MyProg", "Metrics", "Form1Left", Form1.Left /
Screen.Width
    SaveSetting "MyProg", "Metrics", "Form1Height", Form1.Height /
Screen.Height
    SaveSetting "MyProg", "Metrics", "Form1Width", Form1.Width /
Screen.Width
    End
End Sub

--

Use of my Email address for unsolicited commercial purposes
is an invasion of my privacy and will result in legal action.

<URL: http://www.*-*-*.com/ ~medmonds>

        In {*filter*}space, no one knows you're Canadian, eh?



Thu, 23 Sep 1999 04:00:00 GMT  
 Adjust forms to users' screen resolution



Quote:
> I developed a VB 4.0 program while my monitor's resoltion was 800 X 600.
> One of my users complained he could not see some of the controls on
> certain forms -  his monitor is set to 600 X 480. Is there any way for
> the program to adjust to the resolution of the monitor?

Here is a piece of code that I came across that might help:
   '
   ' Size form on screen, use 640x480 as target dimensions.
   '
   Width = 640 * Screen.TwipsPerPixelX
   If Screen.Height > 480 * Screen.TwipsPerPixelY Then
      Height = 480 * Screen.TwipsPerPixelY
   Else
      Height = Screen.Height
   End If


Thu, 23 Sep 1999 04:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Adjusting forms / controls for different screen resolutions.

2. Adjust to screen resolution

3. problem adjusting screen resolution

4. Determining user's screen resolution at runtime

5. Screen resolution auto adjusting?

6. Adjusting VB for different screen resolutions

7. VB 3.0 help: adjusting control size to screen resolution

8. Adjusting for Screen Resolutions

9. How to adjust control sizes and dimensions to suit different screen resolutions

10. Adjusting controls to different screen-resolutions

11. Adjusting controls to different screen-resolutions

12. User forms and screen resolutions

 

 
Powered by phpBB® Forum Software