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 (e. g. RadPdfViewer, RadSpreadsheet). This can occur, for example, when exporting data, loading a document, or instantiating types from assemblies used by:
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
You can choose between two approaches:
1. Make the application explicitly DPI-aware
With this approach your app will look smaller when started. It will 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, you should explicitly set the application to be DPI-unaware
[C#] 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%.