Userform controls and Windows display text size setting

GJL

New Member
Joined
Mar 26, 2011
Messages
17
Normally I keep my Windows display text size setting at 125% (in Windows 7, Personalize | Display).

But if I lay out a userform with controls while on that computer, then run it on another computer with the default setting (100%), text seems to become bigger, or maybe the controls holding them become smaller. Anyway, text is cropped in labels, listboxes get vertical scrollbars they don't have on my computer, etc. Controls carefully laid out to work together, such as an edit box right next to a listbox item named "Other:", are positioned all wrong relative to each other.

Why would the text seem to get bigger when going to a smaller text size setting?

And, what's the best practice when developing for use by others on other computers? Default 100%? Smaller than 100% to cover users who may have their Windows text size set smaller?

Aside from leaving gobs of white space, is it possible to make text in dialog controls look the same size regardless of the Windows text size setting?


Thanks,

Greg
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Normally I keep my Windows display text size setting at 125% (in Windows 7, Personalize | Display).

But if I lay out a userform with controls while on that computer, then run it on another computer with the default setting (100%), text seems to become bigger, or maybe the controls holding them become smaller.

I haven't tested, but if you design at 100% does it then appear OK when you set your display back to 125%? From the little I've read, Win7/Office generally upscales well enough, at least with its native controls.
 
Upvote 0
No, it doesn't. When the user sets the font setting from "Normal" to "Large" or "Extra Large", the userform clips. Exactly as in the OP.

Mike's solution sounded real promising. Dave's did too until I realized none of the parameters for "GetSystemMetrics" appeared to apply.

This is going to pose problems if I try to pitch my tool at work and somebody with bad eyes tries it out and sees only half the buttons on the form.
 
Upvote 0
For simple objects like Command Buttons, substituting a picture (image) of the button should solve the scaleing issues.
 
Upvote 0
Strange. I couldn't replicate the problem. Change the Text size on the CP - Display to extra large but the Buttons and all other userform controls styed the same. No clipping or text size was changed.
 
Upvote 0
The problem appears only to be occuring on some computers. Even separate computers running the same OS (XP). I've seen it happen a bunch of different times, I really wish I could find the source of the problem to make sure it doesn't happen anymore.

Bruce: I gave that a shot, and I have a version to test out the next time I encounter the problem. I don't know if it will help (I don't know why pictures wouldn't clip if buttons do), but I appreciate your input just the same.
 
Upvote 0
Glory, you have been very persistant (I was away). My apologies for being some what cryptic. The following code is borrowed and new and took some considerable time to google, trial and error, and debug. It seems to work well and I would appreciate any feedback to the contrary. See the manual adjust to suit areas especially the numbers.
HTH. Dave
Module code...
Code:
Public Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Long) As Long
Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1
Public X  As Long
Public Y  As Long

Public Type ControlPositionType
    Left As Single
    Top As Single
    Width As Single
    Height As Single
    FontSize As Single
End Type

Public m_ControlPositions() As ControlPositionType
Public m_FormWid As Double
Public m_FormHgt As Double

' Save the form's and controls' dimensions.
Public Sub SaveSizes(UF As Variant)
Dim i As Integer
Dim ctl As Control
    ' Save the controls' positions and sizes.
    ReDim m_ControlPositions(1 To UF.Controls.Count)
    i = 1
    
    For Each ctl In UF.Controls
        With m_ControlPositions(i)
                .Left = ctl.Left
                .Top = ctl.Top
                .Width = ctl.Width
                .Height = ctl.Height
                On Error Resume Next
                .FontSize = ctl.Font.Size
                On Error GoTo 0
        End With
        i = i + 1
    Next ctl

    ' Save the form's size.
    m_FormWid = UF.Width
    m_FormHgt = UF.Height
End Sub
userform code...
Code:
' Arrange the controls for the new size.
Private Sub ResizeControls(UF As Variant)
'userform code
Dim i As Integer
Dim ctl As Control
    ' Get the form's current scale factors.
    x_scale = UF.Width / m_FormWid
    y_scale = UF.Height / m_FormHgt

    ' Position the controls.
    i = 1
    For Each ctl In Controls
        With m_ControlPositions(i)
                ctl.Left = x_scale * .Left
                ctl.Top = y_scale * .Top
                ctl.Width = x_scale * .Width
                    ' Cannot change height of ComboBoxes.
                    ctl.Height = y_scale * .Height
                On Error Resume Next
                ctl.Font.Size = y_scale * .FontSize
                On Error GoTo 0
        End With
        i = i + 1
    Next ctl
End Sub
Private Sub UserForm_Initialize()
Dim Wtemp As Double, HTemp As Double
Call SaveSizes(UserForm1) 'adjust to userform name
X = GetSystemMetrics(SM_CXSCREEN)
Y = GetSystemMetrics(SM_CYSCREEN)
Wtemp = (X - 1024) / 1024
Wtemp = 0.8 - Wtemp / 2 * 0.8 'adjust .8 to suit
HTemp = (Y - 768) / 768
HTemp = 0.9 - HTemp / 2 * 0.9 'adjust .9 to suit
Me.Width = Application.UsableWidth * Wtemp
Me.Height = Application.UsableHeight * HTemp
End Sub
Private Sub UserForm_Resize()
Call ResizeControls(UserForm1) 'adjust to suit
End Sub
 
Upvote 0
Dave -

I haven't been able to track down a PC where I'm at now that suffers from this problem. Was the problem occurring on your computer when you tested this code? (when you set the font sizes to large or extra large).

It looks like you used the pixel dimensions on the user's display to set the size of the form. Would the resolution affect this issue? Because I'm 100% sure it was caused by the font settings.

Anyway, thanks very much for responding back. This issue seems like it must be important, since it will affect anybody trying to use userforms (at least on some XP machines).
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top