Back to Devexpress

WindowsFormsSettings.SetPerMonitorDpiAware() Method

windowsforms-devexpress-dot-xtraeditors-dot-windowsformssettings-2fc2237c.md

latest7.2 KB
Original Source

WindowsFormsSettings.SetPerMonitorDpiAware() Method

Enables “Per-Monitor (v2)” DPI awareness mode for the process if it runs on versions greater than Windows 10 Creators Update (build 1703). On older Windows OS versions, enables system DPI awareness mode.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.Utils.v25.2.dll

NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core

Declaration

csharp
public static void SetPerMonitorDpiAware()
vb
Public Shared Sub SetPerMonitorDpiAware

Remarks

Call this method on the application startup.

csharp
static class Program {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() {
        WindowsFormsSettings.SetPerMonitorDpiAware();
        //...
        Application.Run(new Form1());
    }
}
vb
Public Class Form1
    Shared Sub Main()
        WindowsFormsSettings.SetPerMonitorDpiAware()
        '...
        Application.Run(New Form1) 'Specify the startup form
    End Sub
End Class

To ensure the DPI awareness mode is correctly set up and activated, we recommend to use the DevExpress Project Settings Page.

The SetPerMonitorDpiAware method can apply different DPI awareness modes depending on the Windows version (to check your version, press the “Ctrl+R” hotkey and type “winver”).

  • On Windows 10, version 1607 and later, the SetPerMonitorDpiAware method enables “Per-Monitor (v2)” DPI awareness mode by calling the SetProcessDpiAwarenessContext WinApi function.

  • On older Windows OS versions, the SetPerMonitorDpiAware method enables system DPI-awareness (this method is equivalent to the WindowsFormsSettings.SetDPIAware method in this case).

See Graphics Performance and High DPI and High DPI Desktop Application Development on Windows for information on DPI awareness modes.

The following code snippets (auto-collected from DevExpress Examples) contain references to the SetPerMonitorDpiAware() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-memo-editor-advanced-mode/CS/MemoEditSample/Program.cs#L11

csharp
static void Main() {
    DevExpress.XtraEditors.WindowsFormsSettings.SetPerMonitorDpiAware();
    Application.EnableVisualStyles();

winforms-textedit-advanced-mode/CS/TextEditSample/Program.cs#L11

csharp
static void Main() {
    DevExpress.XtraEditors.WindowsFormsSettings.SetPerMonitorDpiAware();
    Application.EnableVisualStyles();

word-document-api-examples/CS/Program.cs#L20

csharp
Application.SetCompatibleTextRenderingDefault(false);
WindowsFormsSettings.SetPerMonitorDpiAware();
Application.Run(new Form1());

pdf-viewer-get-page-info/CS/pdf-viewer-sticky-note/Program.cs#L22

csharp
DevExpress.UserSkins.BonusSkins.Register();
WindowsFormsSettings.SetPerMonitorDpiAware();
Application.Run(new Form1());

connect-winforms-grid-to-dotnetcore-service/CS/WinForms.Client/Program.cs#L14

csharp
{
    WindowsFormsSettings.SetPerMonitorDpiAware();
    WindowsFormsSettings.DefaultLookAndFeel.SetSkinStyle(SkinStyle.WXI);

winforms-memo-editor-advanced-mode/VB/MemoEditSample/Program.vb#L15

vb
Shared Sub Main()
    DevExpress.XtraEditors.WindowsFormsSettings.SetPerMonitorDpiAware()
    Application.EnableVisualStyles()

winforms-textedit-advanced-mode/VB/TextEditSample/Program.vb#L15

vb
Shared Sub Main()
    DevExpress.XtraEditors.WindowsFormsSettings.SetPerMonitorDpiAware()
    Application.EnableVisualStyles()

word-document-api-examples/VB/Program.vb#L16

vb
Application.SetCompatibleTextRenderingDefault(False)
Call WindowsFormsSettings.SetPerMonitorDpiAware()
Call Application.Run(New Form1())

pdf-viewer-get-page-info/VB/pdf-viewer-sticky-note/Program.vb#L18

vb
DevExpress.UserSkins.BonusSkins.Register()
Call WindowsFormsSettings.SetPerMonitorDpiAware()
Call Application.Run(New Form1())

connect-winforms-grid-to-dotnetcore-service/VB/WinForms.Client/Program.vb#L14

vb
Sub Main()
    Call WindowsFormsSettings.SetPerMonitorDpiAware()
    WindowsFormsSettings.DefaultLookAndFeel.SetSkinStyle(SkinStyle.WXI)

See Also

SetDPIAware()

WindowsFormsSettings Class

WindowsFormsSettings Members

DevExpress.XtraEditors Namespace