SftBox/OCX 6.0 is fully Per-Monitor v2 DPI-aware. A combo box control hosted on a Per-Monitor v2 aware top-level window follows the DPI of the monitor it is on and re-renders 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, fonts and pixel dimensions it provides. Two opt-in properties let the caller hand the images and the pixel dimensions over to the control as well.
The host application must declare Per-Monitor v2 DPI awareness. This is the single most common reason high-DPI applications do not re-render correctly when moved between monitors of different DPI. Without a Per-Monitor v2 declaration, Windows keeps the process in System-aware mode: the DPI is fixed for the process lifetime, the control does not observe DPI changes, the DPIChanged event is never fired, and high-DPI monitors render at System-DPI sizes stretched by Windows.
Declare Per-Monitor v2 awareness in the host application's manifest, for example:
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness> <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
In a .NET project, this corresponds to selecting Per Monitor V2 for the application's DPI awareness. The DPI property returns the control's current monitor DPI (96 at 100%, 120 at 125%, 144 at 150%, 192 at 200%). If the returned value never changes as the window is dragged between monitors with different scale factors, the host is not in Per-Monitor v2 mode.
When the host is Per-Monitor v2 aware, the control scales the metrics it owns for the DPI of its monitor, without any caller involvement: the scroll bars, the drop down button, its built-in arrow and the sizing box of the drop down portion. The drop down portion always uses the DPI of the combo box. The height of the control is derived from its font, so it follows the font the container supplies for the new DPI.
Two independent properties decide whether caller-supplied images and caller-supplied pixel dimensions also scale with DPI. Both use SftBoxScalingConstants and both default to scalingSftBoxAsIs, which preserves the behavior of applications written for earlier versions.
| Property | Covers | scalingSftBoxAsIs (default) | scalingSftBoxStretch |
|---|---|---|---|
| ImageScaling | Every image the control draws: item and label pictures, cell pictures, column header, row header and row/column header pictures, drop down button pictures and expand/collapse buttons. | Images are drawn at their native pixel size. Images prepared at 96 DPI look physically smaller on a high-DPI monitor. | Images are scaled by current DPI / 96 when they are drawn. |
| PixelScaling | Pixel dimensions defined by the application: column widths (Column.WidthPix and MinWidthPix), the indentation (Items.IndentationPix), the row header width (RowHeaders.WidthPix), the horizontal scrolling extent (Items.HorizontalExtent), the minimum and maximum item height (Items.MinHeightPix and MaxHeightPix, and the same Item properties) and the width and height of the drop down portion (DropDown.WidthPix and HeightPix), as well as the properties that define the same dimensions in container units. | The values are used as set, in physical screen pixels. | The values are interpreted as 96-DPI reference pixels. A column width of 100 is 100 pixels at 100%, 150 pixels at 150% and 200 pixels at 200%. The property values themselves do not change, so saved settings stay portable. |
When the control's monitor DPI changes, the drop down portion is hidden if it is shown and the DPIChanged event is fired. The application should assign a font sized for the new DPI if the container does not already do so (the control does not own the application's font); the control adjusts its height to the new font. Fonts defined for the edit control portion, the column headers, the row headers and individual cells are defined again in the same way. Pictures and pixel dimensions need no further action when the two scaling properties are set to scalingSftBoxStretch; with scalingSftBoxAsIs, the application defines pictures for the new DPI and sets the pixel dimensions again, scaled for the new DPI, if needed.
Per-Monitor v2 DPI awareness requires Windows 10 version 1703 or later.