The WinForms Notepad Project: High-DPI Support (Premium)

When Windows Forms first appeared with the initial release of the .NET Framework in early 2002, Windows XP was still brand new and high DPI displays were several years away from being the norm in the PC market. For this reason, Windows Forms applications can look fuzzy when run on high DPI displays, and this is something we’ve seen with our Notepad control.

Fortunately, Microsoft added support for high DPI displays to Windows Forms via updates to the .NET Framework, and it has improved that support over the years as Windows 8 and then Windows 10 arrived. And as of .NET Framework 4.7, high DPI support in Windows Forms is pretty much complete and supports the latest OS features related to this functionality.

The issue is that it’s not enabled by default. So let’s enable it.

We need to make two changes, one each to two different application configuration files.
Application manifest
First, we need to add an entry to our application’s manifest file. As described by Microsoft, the “application manifest is an XML file that describes and identifies the shared and private side-by-side assemblies that an application should bind to at run time … Application manifests may also describe metadata for files that are private to the application.” That may or may not mean anything to you, but one thing .NET-based applications have used an application manifest file for over the years is to support the new visual styles for controls and other UI elements that arrived with certain Windows versions. So what we’re using it for here is somewhat similar to that.

To access our application’s manifest, right-click the project name in the Solution Explorer and then select Add > New Item from the context menu that appears. The Add New Item window appears.

Select “Application Manifest File” and then click Add. (Don’t change the name.) A file named app.manifest now appears under the project in Solution Explorer, and it opens in the code editor.

This file includes numerous declarations that are commented out using the “<!--” start comment tag and the “-->” end comment tag. We need to remove the comments around two of them.

The first reads like so:
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
So remove the “<!--” and “-->” and text from the second of those two lines. It should now read like so, and explicitly add support for Windows 10 (and previous Windows versions) to our app.
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
Below that, you’ll see another commented out block related to DPI-awareness. It currently looks like so:
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
   <windowsSettings>
     <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
   </windowsSettings>
</a...

Gain unlimited access to Premium articles.

With technology shaping our everyday lives, how could we not dig deeper?

Thurrott Premium delivers an honest and thorough perspective about the technologies we use and rely on everyday. Discover deeper content as a Premium member.

Tagged with

Share post

Please check our Community Guidelines before commenting

Windows Intelligence In Your Inbox

Sign up for our new free newsletter to get three time-saving tips each Friday

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Thurrott © 2024 Thurrott LLC