Resolving Unexpected Per-Monitor DPI Awareness in WinForms Apps
Environment
| Product Version | Product | Author |
|---|---|---|
| All | Document Processing Libraries | Yoan Karamanov |
Description
A WinForms application may appear smaller (or larger) at runtime after using Document Processing Libraries (DPL) functionality or DPL-dependent Telerik controls (for example, RadPdfViewer, RadSpreadsheet). This can occur when you export data, load a document, or initialize types from assemblies used by these controls.
These dependencies internally rely on WPF assemblies where DPI awareness is enabled at the assembly level. The moment a type from such an assembly is initialized, the hosting WinForms process can become DPI-aware.
Solution
Choose between two approaches:
1. Make the Application Explicitly DPI-Aware
With this approach your application looks smaller when started. It does not look blurry on HDPI displays. Detailed information is available in the DPI Support article.
2. Keep (or Force) the Application DPI-Unaware (Windows 10 Only)
This approach works only on Windows 10. If you intend to use your application on machines where the DPI scaling is larger than 100 percent, explicitly set the application to be DPI-unaware:
Force Process DPI Unaware Before Using a Document Processing Type
private void workbookTestButton_Click(object sender, EventArgs e)
{
SetProcessDpiAwareness(_Process_DPI_Awareness.Process_DPI_Unaware);
Workbook wb = new Workbook();
}
[DllImport("shcore.dll")]
static extern int SetProcessDpiAwareness(_Process_DPI_Awareness value);
enum _Process_DPI_Awareness
{
Process_DPI_Unaware = 0,
Process_System_DPI_Aware = 1,
Process_Per_Monitor_DPI_Aware = 2
}
None of the above approaches affect the application when the scaling is set to 100%.