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.


How to fix it
- Go the the Forms designer, then select your Form (by clicking at its title bar)
- Press F4 to open the Properties window, then locate the AutoScaleMode property
- Change it from Font (default) to Dpi.
Now, go to Program.cs (or the file where your Main method is located) and change it to look like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace Classification.BoW { static class Program { [STAThread] static void Main() { if (Environment.OSVersion.Version.Major >= 6) SetProcessDPIAware(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } [System.Runtime.InteropServices.DllImport("user32.dll")] private static extern bool SetProcessDPIAware(); } } |
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
- http://stackoverflow.com/questions/13228185/winforms-high-dpi-blurry-fonts
- http://stackoverflow.com/questions/27933868/creating-dpi-aware-c-sharp-clickonce-application-with-winforms
- http://blogs.telerik.com/winformsteam/posts/14-02-11/winforms-scaling-at-large-dpi-settings-is-it-even-possible-
- http://stackoverflow.com/questions/27933868/creating-dpi-aware-c-sharp-clickonce-application-with-winforms