Resolved Blurry text and shortened form

MPIon

Well-known member
Joined
Jun 13, 2020
Messages
79
Location
England
Programming Experience
10+
I have one particular Visual Studio c# project where the text is blurry and the form is shorter than in design mode.
I am running on a 4K Monitor at 200% scaling. I have two other projects that both have clear text and the correct form size.
The text is actually clear in design mode, but only blurred when the code is run - both in debug mode and release mode.
Can't see any difference between the set up of the projects.
Form at design time :-
Screenshot 2025-05-16 085952.png

Form at run time, with line of text shown :-
Screenshot 2025-05-16 091052.png


Any help on this would be appreciated.
p.s. Restarting VS with 100% scaling makes the problem even worse as the text is blurry even in design mode.
 

Attachments

  • Screenshot 2025-05-16 090042.png
    Screenshot 2025-05-16 090042.png
    8.7 KB · Views: 0
  • Screenshot 2025-05-16 090042.png
    Screenshot 2025-05-16 090042.png
    8.7 KB · Views: 0
*** removed unnecessary quote ***

You're encountering an issue with Windows Forms applications on high-resolution displays with scaling enabled, where the application's DPI awareness settings don't match the system settings at runtime. This often leads to blurry text and incorrect form sizing. The fact that it's specific to one project points to a configuration difference within that project.
DPI Awareness Settings in app.config or app.manifest:

Modern .NET Framework applications (starting with 4.7) and .NET (Core) use settings in the app.config file to control High DPI awareness. Older applications might use an app.manifest file.

Check app.config:Open the app.config file in your problematic project and look for a <System.Windows.Forms.ApplicationConfigurationSection> element. Within this section, there might be a <add key="DpiAwareness" value="..." /> entry.

PerMonitorV2 is the recommended setting for applications that need to adapt to different DPI settings when moved between monitors with varying scales. This is likely what you want for a 4K monitor with 200% scaling.

System means the application scales based on the primary display's DPI when it starts and doesn't adjust if moved to a different monitor. This can cause blurriness and incorrect sizing.

DPIUnaware means the application assumes 100% scaling (96 DPI) regardless of the actual display settings. Windows will then bitmap stretch the application, leading to significant blurriness.

Check app.manifest: If you don't have the ApplicationConfigurationSection in app.config or are using an older .NET Framework, check if your project has an app.manifest file. Look for a <dpiAwareness> or <dpiAware> element within the <windowsSettings> section. The value here also dictates the DPI awareness mode.

Compare with Working Projects: Examine the app.config and app.manifest files in your working projects to see how their DPI settings are configured. They likely have a setting that is more appropriate for high DPI displays.

Action to take that may help you:

If your problematic project has DPIUnaware or System set, try changing it to PerMonitorV2 in app.config (for .NET Framework 4.7+) or configure the manifest accordingly.

If the working projects have different, more appropriate settings, try copying those settings to the problematic project.

Application.SetHighDpiMode in Program.cs to understand:

In newer .NET versions, the DPI awareness can also be set programmatically at the application entry point (usually in Program.cs) using Application.SetHighDpiMode(HighDpiMode.<Mode>).

Open Program.cs and look for this line, often before Application.Run().

Compare the HighDpiMode used in the problematic project with your working projects. HighDpiMode.PerMonitorV2 is the preferred setting.
Actions continued...

Ensure the problematic project is using HighDpiMode.PerMonitorV2 if you are setting DPI awareness programmatically.

Compatibility Settings (Less Likely for a New Project Issue):

Windows compatibility settings can sometimes override application-level DPI settings. While less likely to be the sole cause for a project-specific issue unless it was manually applied, it's worth checking.

Find the executable file of your problematic application in the bin folder (either Debug or Release).
Right-click the executable and select "Properties."
Go to the "Compatibility" tab.
Click on "Change high DPI settings."
See if any "High DPI scaling override" options are checked.
Actions continued...

If any override is enabled, try disabling it and see if the issue is resolved.

AutoScaleMode Property of the Form:

The AutoScaleMode property of your forms can also influence how controls are scaled with DPI changes. The common settings are Font and Dpi.

Open the designer for your problematic form.
Select the form itself (click on the form's title bar).
In the Properties window, check the AutoScaleMode property.
Actions continued...

While Dpi is often recommended for better high DPI scaling, inconsistencies can sometimes arise. Compare this setting across your projects. If they differ, try making them consistent.

Visual Studio Designer vs. Runtime Differences:

It's important to note that the Visual Studio WinForms designer itself has had historical issues with high DPI scaling. The designer might not always accurately reflect how the form will look at runtime, especially with complex layouts or custom controls. The info bar you mentioned in Visual Studio offering to restart with 100% scaling is a testament to this. However, your issue is the reverse – it looks good in the designer but bad at runtime, which strongly points back to the application's runtime DPI configuration.

Troubleshooting Steps to help....

Focus on the Problematic Project:
Concentrate your efforts on identifying differences in the DPI configuration settings within the problematic project's app.config, app.manifest, and Program.cs compared to the working projects.

Simplify for Testing: If possible, create a new, simple WinForms project targeting the same .NET version as the problematic project. Add a form with a few controls and run it on your 4K monitor. See if it exhibits the same blurry text and scaling issues. If the new project works correctly, carefully compare its default configuration files with your problematic project.

Examine Project File (.csproj): Although less common for direct DPI settings, open the .csproj file of both projects in a text editor and look for any differences related to DPI or application manifests that might be explicitly included or excluded.
By systematically checking these configuration points and comparing them between your working and non-working projects, you should be able to pinpoint the setting that is causing the incorrect runtime behavior on your high DPI display. The most likely culprit is an incorrect or missing DPI awareness setting that tells Windows how your application should handle scaling at runtime.
 
Last edited by a moderator:
Justin,
Thanks for your extensive reply.
I set the compatibility mode to System Enhanced in High DPI Scaling Override, which seems to have corrected the blurry text in some of the fields. I'll see if there is a different Font or Point size used in the others.

I realise now that this particular project was built using Net 4.8, whereas as all my other projects are using Net 8 and don't seem to have the same problem.
I tried using the automated Upgrade option on the project to convert to Net 8, which seemed to work successfully, but the forms won't load.

Clearly the Upgrade Option does not work properly.

I've spent some time trying to resolve the issue without success, and now am not sure whether to continue with the Net 4.8 version in compatibility mode or carry on with the Net 8 version.


Screenshot 2025-05-16 171434.png
 
I've always thought that all the VS project upgrade wizards were a "best effort" type porting operation. It doesn't guarantee a successful upgrade, but it will do a lot of the boilerplate stuff and heavy lifting to get the majority of the work done.

Personally, I don't trust the upgrade wizards. I choose to start from a fresh project/solution and port the code by hand incrementally, and commit code as I go along. That way when I hit a snag, I know that the problem was due to the last step I'd performed and I can work on that issue alone instead of having to deal with hundreds of errors/warnings after the wizard has run.

Maybe Justin has an AI that can also do a similar style upgrade in incremental steps and fix issues as it goes along, instead of the Microsoft upgrade wizard that trying to do everything in a Big Bang.
 
Thanks Skydiver,

I am adopting the incremental approach of starting with a blank Net 8 project and copying forms and code over bit by bit.
So far, all the text looks very sharp and the forms are not truncated at all.

Its a pity the Wizard did not work properly, as this is now going to involve a lot of work and I have to figure out all the bits of code I wrote years ago.
Fortunately, it is not a critical project and I can live with the blurry text until I get the new version up and running.
 
For me, getting to see old code helps reinforce things which were done right, and also uncovers things which could have been done better. Yeah, it can look like drudgery at times, though.
 
Back
Top Bottom