HeaderPane
Main
Hide
Share Link
Print

Per-Monitor DPI and Scaling

SftDate/OCX 2.0 is Per-Monitor v2 DPI-aware. An SftDate or SftCalendar control hosted on a Per-Monitor v2 aware top-level window follows the DPI of the monitor it is on and redraws when its window moves to a monitor of a different DPI or when the system DPI changes. The control owns the metrics it controls; the caller owns the images and fonts it provides.

Host Setup

The host application must declare Per-Monitor v2 DPI awareness. Without it, Windows keeps the process in System-aware mode: the DPI is fixed for the process lifetime, the controls do not observe DPI changes, the DPIChanged event never occurs, and high-DPI monitors render at System-DPI sizes stretched by Windows. Visual Studio's default application manifest does not declare Per-Monitor v2 awareness - the developer must opt in explicitly.

A C++ application declares it in its application manifest; both elements are usually included for back-compatibility with older Windows 10 builds:

<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
  <asmv3:windowsSettings>
    <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
    <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
  </asmv3:windowsSettings>
</asmv3:application>

In a Visual Studio C++ project, set Project Properties -> Manifest Tool -> Input and Output -> DPI Awareness to None when the manifest file is added as an Additional Manifest File, so the manifest tool does not add a second <dpiAware> element; a manifest with two of them keeps the application from starting.

A Windows Forms application for .NET Framework 4.7 or later becomes Per-Monitor v2 aware with this setting in its app.config file, together with Windows 10 compatibility in its application manifest; a .NET 10 application calls Application.SetHighDpiMode(HighDpiMode.PerMonitorV2) before it creates its first window:

<System.Windows.Forms.ApplicationConfigurationSection>
  <add key="DpiAwareness" value="PerMonitorV2" />
</System.Windows.Forms.ApplicationConfigurationSection>

Quick check at runtime: the DPI property (DPI, DPI) returns the DPI of the control's monitor - 96 at 100%, 120 at 125%, 144 at 150%, 192 at 200%. If the returned value never changes as you drag the window between monitors with different scale factors, the host is not in Per-Monitor v2 mode.

Windows Forms Scaling

Windows Forms scales a form and its controls when the form is shown at a DPI other than the one it was designed at, but it does not scale ActiveX controls (AxHost). The samples therefore override the form's ScaleControl method to scale the positions and widths of the controls; their heights follow their fonts (see AutoSize):

protected override void ScaleControl(SizeF factor, BoundsSpecified specified) {
    base.ScaleControl(factor, specified);
    foreach (Control c in Controls)
        if (c is AxHost)
            c.SetBounds((int)Math.Round(c.Left * factor.Width), (int)Math.Round(c.Top * factor.Height), (int)Math.Round(c.Width * factor.Width), c.Height);
}

The samples place all controls directly on the form; for ActiveX controls inside a container control, such as a panel or a group box, the loop also goes through the Controls of that container. The .NET samples are System DPI aware, so Windows Forms scales them for the system DPI when they open.

What Scales Automatically

When the host is Per-Monitor v2 aware, the controls scale the metrics they own for the DPI of their monitor, without any caller involvement: the field's border, buttons and check box, the calendar's layout, its previous and next buttons, the time list and the clock face. A field closes its dropdown when its DPI changes. A dropdown opened on another monitor than its field uses the DPI of that monitor, with the field's fonts scaled to it.

What the Caller Controls

The ImageScaling property (ImageScaling, ImageScaling) defines how the pictures of special dates and of the DayFormatting event follow the DPI:

SettingDescription
scalingSftDateAsIs (default)Pictures are drawn at their native pixel size. Pictures supplied for 96 DPI look physically smaller on a high-DPI monitor.
scalingSftDateStretchPictures are treated as designed for 96 DPI and are scaled by DPI / 96.

No property of SftDate/OCX takes a pixel size from the application: the controls size all their parts from the font and the DPI of the monitor.

Caller Responsibilities on DPI Change

When the DPI of a control changes, the DPIChanged event occurs (DPIChanged, DPIChanged); its DPI parameter (e.dPI in .NET) is the new DPI. The application should:

  • assign a font sized for the new DPI to the control's Font property if it defined the control's font and the container does not already supply one (the control does not own the application's font); a field adjusts its height for the new font, and an SftCalendar control with automatic sizing (AutoSize) its size,
  • assign the calendar and title fonts again (Font, TitleFont) if it defined them, and use fonts for the new DPI in the DayFormatting event,
  • if ImageScaling is scalingSftDateStretch, no further action is needed for pictures - the control scales them automatically,
  • if ImageScaling is scalingSftDateAsIs and the application wants crisp pictures, define the pictures again using images for the new DPI (and call RefreshDays for the pictures of the DayFormatting event),
  • lay out the form again if the size of an SftCalendar control with automatic sizing changed.

The DPI property returns the new DPI while the event is handled.

Platform note: Per-Monitor v2 DPI awareness requires Windows 10 version 1703 or later.


Last Updated 11/29/2026 - (email)
© 2026 Softel vdm, Inc.