How to fix blurry Windows Forms Windows in high-dpi settings

If you have just opened one of your previous applications in your brand new computer with a very high-dpi monitor, perhaps you will find out that your interface that previously worked perfectly is now utterly broken and/or blurry.

This might be the case, for example, if you just tried to open an old Windows.Forms application in your brand new Surface Pro computer.

winforms-dpi-off
Windows.Forms (WinForms) application in a high-dpi display. If you have your DPI set to 150%, your form might now look like this.

 

winforms-dpi-on
Same WinForms application after applying the fix detailed here.

 

How to fix it

  1. Go the the Forms designer, then select your Form (by clicking at its title bar)
  2. Press F4 to open the Properties window, then locate the AutoScaleMode property
  3. Change it from Font (default) to Dpi.

winforms-dpi-turning

Now, go to Program.cs (or the file where your Main method is located) and change it to look like

Save and compile. Now your form should look crispy again.

I encountered this problem while opening and editing Accord.NET sample applications in Visual Studio in a Surface 3 Pro.

Related resources

17 Comments

  1. Thanks much… everything looks so much better now!

    This was a problem on my windows 8.1 box, and when I upgraded to 10, it was still an issue – blurry, and my controls were getting clipped/shrunken with lines of text cut in half and other weird artifacts that all looked fine in the designer. I checked the settings on my machine and yup, 150%. So I added the interop and changed the form AutoScaleMode to DPI as you recommended above, and >poof< like magic all the weirdness went away. Far far away!

  2. For anyone interested in getting rid of blurry forms in VB.net:
    – Find Application.Designer.vb (instead of Program.cs)
    – Insert:

    ‘Inside Public Sub New(), AFTER the line MyBase.New(…
    If (Environment.OSVersion.Version.Major >= 6) Then
    SetProcessDPIAware()
    End If

    ‘Outside of Public Sub New()

    Private Shared Function SetProcessDPIAware() As Boolean
    End Function

    Cheers 🙂

  3. Shit, it got rid of my line with System.Runtime.InteropServices.DllImport(“user32.dll”)
    You need this inside pointy brackets or inequality signs () instead of quare brackets above the definition of SetProcessDPIAware() function

  4. Team,

    I am having exactly the same problem as the link below and I have finally come to the conclusion that I had to implement the

    SetProcessDPIAware() function on one of the windows forms encompassing the report viewer. I tried doing the changes to the application manifest file but it is not compatible with the Click Once Deployment technique.

    https://social.msdn.microsoft.com/Forums/en-US/51ce2679-5671-41c3-91d9-b4636d16b94e/rdlc-print-layout-size-varies-with-resolution-on-surface-pro-win-81-winforms?forum=sqlreportingservices.

    After implementation, i found that there the font sizes have been minimized and there are some misalignment in other forms too.

    Also I just want the report print layout to scaled to the width which is just one form. Is there any way I can just apply to this form and leave others untouched ?

Leave a Reply

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