
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?