From: Brian on 2 Feb 2010 23:58
The problem is that only the User form changes size and not the entire
window. When I get the User Form to fit the screen, 1/2 of the Window is
completely off the screen where you can not close it without moving it.
> Hi Brian,
> The code below finds the screen resolution and then uses a proportional
> method of setting the form size. Unfortunately there are a few hitches.
> Zoom only zooms the controls on the form and not the form.
> Screen resolutions for width and height are not proportional.
> Due to the above my proportional method is not accurate. Especially using
> the average for the zoom but for forms that don't fill the screen it is not
> too bad.
> You might find it better to use Select Case and have fixed settings for each
> You also might want to re-set the Top and Left parameters that I have
> commente out.
> However, you did say that if given a pointer you can usually work it out so
> lets know how you go and I'll be interested in your results.
> Video display code from the following link
> Option Explicit
> 'API & Public Const declarations at top of module
> Declare Function GetSystemMetrics32 Lib "user32" _
> Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
> Public Const SM_CXSCREEN = 0
> Public Const SM_CYSCREEN = 1
> Sub Show_Userform()
> Dim vidWidth As Long
> Dim vidHeight As Long
> Dim dblMultWdth As Double
> Dim dblMultHt As Double
> Dim dblZoom As Double
> vidWidth = GetSystemMetrics32(SM_CXSCREEN)
> vidHeight = GetSystemMetrics32(SM_CYSCREEN)
> '1152 and 864 is initial setup resolution
> dblMultWdth = vidWidth / 1152
> dblMultHt = vidHeight / 864
> dblZoom = (dblMultWdth + _
> dblMultHt) / 2 'Average
> With UserForm1
> .Zoom = 100 * dblZoom
> .Width = .Width * dblMultWdth
> .Height = .Height * dblMultHt
> '.Top 'For Info. Not used here
> '.Left 'For info. Not used here
> End With
> End Sub
From: OssieMac on 3 Feb 2010 00:24
Did you change any of the code? If you make any alterations to the code and
it does not work then please post it in case that is where the problem is.
All of the code goes in a standard module.
The API declaration and Public const must be at the top of the standard
module before any subs.
Ensure that the zoom property of the form is set to 100 in the forms
properties (or change the 100 in the code to the zoom setting that you have
in the forms properties.)
All properties set by the code are temporary and only last while the form is
You may need to set the forms startup position to zero (manual) like the
following if you set top and left position otherwise it will default to
centre irrespective of top and left settings. My apologies; I should have
included that before.
You should be able to close the form by right clicking in the top bar of the
form and close from the drop down menu if the X is not visible.
Dim vidWidth As Long
Dim vidHeight As Long
Dim dblMultWdth As Double
Dim dblMultHt As Double
Dim dblZoom As Double
vidWidth = GetSystemMetrics32(SM_CXSCREEN)
vidHeight = GetSystemMetrics32(SM_CYSCREEN)
'1152 and 864 is initial setup resolution
dblMultWdth = vidWidth / 1152
dblMultHt = vidHeight / 864
dblZoom = (dblMultWdth + _
dblMultHt) / 2 'Average
.StartUpPosition = 0 'Over ride the centre position
.Zoom = 100 * dblZoom
.Width = .Width * dblMultWdth
.Height = .Height * dblMultHt
'.Top = 200 'For Info. Can use if you want
'.Left = 100 'For info. Can use if you want
From: OssieMac on 3 Feb 2010 00:35
Are you using maximize screen because that is how I tested it?
Also lookup StartUpPosition in help. You might need to set it to one of the
other options in the forms properties instead of re-setting it in the code.
(Note that setting StartUpPosition in the code over rides the setting in the
properties dialog box.)