.NET forms on Windows 7 at 125% zoom level

5.00 avg. rating (94% score) - 1 vote

If you have ever tried to personalize your Windows 7 desktop and chose to zoom to 125%, as per the following screenshot, you’ll perhaps notice that some applications do not display so well:

Believe it or not, the 125% or 150% zoom mode does not simply decrease the dpi of the display and make it look bigger, unlike the advanced display settings in Windows XP:

In fact, when the 125% or 150% zoom mode is set, Windows 7 does (at least) the following two things:

  1. Increase the default font size
  2. Tell every window (including child window) to increase its size

It’s up to the application to handle the change in font size and window size gracefully. If it does not, the application interface may look distorted, with text truncated or displayed outside its designated area and graphics being tiled up or stretched.

Interestingly the 125% or 150% zoom mode cannot be used during a Remote Desktop session.

Effects on .NET forms

Under 125% or 150% zoom, the size of a .NET form will increase proportionally. The following changes will have to be made for the form to display properly:

  1. All form controls should have their Anchor property set appropriately. 
  2. Most importantly, the AutoScaleMode property of every form should be set to Dpi and not Font. AutoScaleMode of user controls can be set to either Dpi or Inherit. 

 If set inappropriately, only the form will resize while the controls do not resize, causing display distortion.

Also, do not open the form designer from inside Visual Studio 2008 under 125% or 150% zoom mode. Otherwise, Visual Studio will “zoom” the form (perhaps in an attempt to obey the Windows settings faithfully) by increasing its Size property and forgets (or is unable) to restore the original size when the zoom mode is set to 100%. If this happens, you’ll have to manually resize every form back to their original size.

I am not sure if it’s a Visual Studio bug, or it’s just supposed to be that way.

5.00 avg. rating (94% score) - 1 vote
ToughDev

ToughDev

A tough developer who likes to work on just about anything, from software development to electronics, and share his knowledge with the rest of the world.

9 thoughts on “.NET forms on Windows 7 at 125% zoom level

  • August 27, 2011 at 2:34 am
    Permalink

    Also, in Visual Studio 2010 designer, if you create custom User Controls and place those on a form using "Medium (125%)" display setting they will, under the "Default" setting have exaggerated widths (scaled using the DPI issue mentioned in this article, no doubt). Meaning, your user control will, likely, wind up with some right side clipping! My Error Provider was on the right side and got clipped. But it was so subtle and all the other controls looked great. New levels of frustrated "works on my machine". Good lord, that was TRICKY to figure out!!! Bug, me thinks ;)

  • August 27, 2011 at 9:22 am
    Permalink

    Todd, thanks for sharing your findings with me :)

  • September 13, 2011 at 2:56 am
    Permalink

    I too was bit with this anomaly of having the display settings in Windows set to 125% on my development machine. After two days of running my budding application on different machines set at 100% resulting in gross distortions and not believing what I was seeing, I finally installed Visual Studio on them so I could check what was really happening in the designer and debugger. I finally realized that pixels weren't pixels and I stumbled on to my 125% setting in Windows Display optins.. Thank you for posting this problem.

  • December 27, 2012 at 11:43 am
    Permalink

    Thank you so much… this was a problem but now working like a charm. :D

  • January 16, 2013 at 9:13 pm
    Permalink

    Is there a way of checking what the text size is set to, something along the lines of checking the screen height, i.e.

    ScreenHeight = Screen.PrimaryScreen.Bounds.Height

    I have an application that needs to re-position GroupBoxes depending on the number of GroupBoxes that are being displayed; the user has the ability to dynamically turn groupboxes on and off. when the display is set to anything other than 100% the positions used is wrong.

    I can't rely on the anchor as its anchor position can change.

  • January 16, 2013 at 10:29 pm
    Permalink

    Hi Martin,

    Unfortunately till this day, I could not find a way to determine the 100% or 125% settings from code. The only workaround other than using the Anchor property is to paint the controls manually. :(

  • January 17, 2013 at 1:26 am
    Permalink

    Hi,

    Well I've had a search and this seems to be one way of doing it.

    What I have found is if I test to see if the text size is set to 120% and if it is I can multiply my X and Y positions by 1.25 and they are then positioned correctly.

    I assume that I can do the same for 150% although I haven't tested that.

    Imports Microsoft.Win32

    Dim ScreenMagnification As RegistryKey

    Dim pRegKey As RegistryKey = My.Computer.Registry.CurrentUser
    pRegKey = pRegKey.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\ThemeManager", False)

    ScreenMagnificationValue = pRegKey.GetValue("LastLoadedDPI")

    If ScreenMagnificationValue = "120" Then
    XOffSet = 1.25
    YOffSet = 1.25
    ElseIf ScreenMagnificationValue = "150" Then
    XOffSet = 1.5
    YOffSet = 1.5
    Else
    XOffSet = 1
    YOffSet = 1
    End If

  • January 4, 2021 at 2:54 pm
    Permalink

    is there a reason for Dimming ScreenMagnification as RegistryKey and then not referencing it again? I’m a bit confused.

  • January 20, 2021 at 4:44 pm
    Permalink

    Hi Martin,

    Thanks for the solution! For creating a ‘ControlPaint.DrawReversibleFrame’ window (e.g. for selection or zooming in) you need to use ‘PointToScreen()’ methods that don’t take the DPI scaling into account.

    For this I need to manually correct is, and thanks to your solution I now can:

    Dim ScreenMagnificationValue = pRegKey.GetValue(“LastLoadedDPI”)
    Dim dpiFactor = CSng(ScreenMagnificationValue) / 96

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>