INTRODUCTION
Sometimes, we set custom scaling to our desktop in order to have comfortable look. However, setting custom scaling could make the text of our winform application blur, as shown in figure below.
![]() |
| Figure 1 |
We can manually make the text clear by setting the application properties. First, right click the application .exe file, go to the "Compatibility" tab, then click the "Change high DPI settings" button, as shown in the figure below.
![]() |
| Figure 2 |
A dialog box pop out, we then check the option as shown in the figure below.
![]() |
| Figure 3 |
After that, we run the application again, the text is shown clear as shown in the figure below, compare to the Figure 1 above.
![]() |
| Figure 4 |
Objective of this article is to create a winform application which overrides high DPI by using C# as shown in the next section.
OVERRIDE HIGH DPI
The C# source code below illustrates MyForm class.
The C# source code below implements the Main method in the MainProgram class.
The C# source code below implements the Main method in the MainProgram class.
The SetProcessDPIAware method must be called before any GUI control is created, and it only supports from Windows Vista or later. Thus, we must check the Windows OS version before the SetProcessDPIAware method is called.
At last, we build and run it. The result is shown as same as Figure 4.
CONCLUSION
Conclusion: To override high DPI, we import the SetProcessDPIAware method from user32.dll file, and call it before any GUI control is created.
REFERENCE
For more information about SetProcessDPIAware function, see SetProcessDPIAware function (winuser.h) | Microsoft Docs.
For more information about EnableVisualStyles method, see Application.EnableVisualStyles | Microsoft Docs.
For more information about RenderWithVisualStyles method, see Application.RenderWithVisualStyles | Microsoft Docs.
For more information about EnableVisualStyles method, see Application.EnableVisualStyles | Microsoft Docs.
For more information about RenderWithVisualStyles method, see Application.RenderWithVisualStyles | Microsoft Docs.







