Class DpiHandler
This handles DPI changes see u.a. Writing DPI-Aware Desktop and Win32 Applications
Inheritance
System.Object
DpiHandler
Namespace: Dapplo.Windows.Dpi
Assembly: Dapplo.Windows.Dpi.dll
Syntax
public sealed class DpiHandler : IDisposable
Constructors
| Improve this Doc View SourceDpiHandler(Boolean)
Create a DpiHandler
Declaration
public DpiHandler(bool needsListenerWorkaround = false)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | needsListenerWorkaround |
Fields
| Improve this Doc View SourceDefaultScreenDpi
This is the default DPI for the screen
Declaration
public const double DefaultScreenDpi = null
Field Value
Type | Description |
---|---|
System.Double |
Properties
| Improve this Doc View SourceDpi
Retrieve the current DPI for the window
Declaration
public double Dpi { get; }
Property Value
Type | Description |
---|---|
System.Double |
IsDpiAware
Check if the process is DPI Aware, an DpiHandler doesn't make sense if not.
Declaration
public static bool IsDpiAware { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
OnDpiChanged
This subject publishes whenever the dpi settings change
Declaration
public IObservable<double> OnDpiChanged { get; }
Property Value
Type | Description |
---|---|
IObservable<System.Double> |
Methods
| Improve this Doc View SourceDispose()
Declaration
public void Dispose()
EnableDpiAwareness()
Turn on the Dpi awareness
Declaration
public static bool EnableDpiAwareness()
Returns
Type | Description |
---|---|
System.Boolean | bool if this is enabled |
GetDpi(IntPtr)
Retrieve the DPI value for the supplied window handle
Declaration
public static int GetDpi(IntPtr hWnd)
Parameters
Type | Name | Description |
---|---|---|
IntPtr | hWnd | IntPtr |
Returns
Type | Description |
---|---|
System.Int32 | dpi value |
ScaleWithDpi(Int32, Double)
Scale the supplied base width according to the supplied dpi
Declaration
public static int ScaleWithDpi(int baseWidth, double dpi)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | baseWidth | int with e.g. 16 for 16x16 images |
System.Double | dpi | current dpi, normal is 96. |
Returns
Type | Description |
---|---|
System.Int32 | Scaled width |
TryEnableNonClientDpiScaling(IntPtr)
public wrapper for EnableNonClientDpiScaling, this also checks if the function is available.
Declaration
public static bool TryEnableNonClientDpiScaling(IntPtr hWnd)
Parameters
Type | Name | Description |
---|---|---|
IntPtr | hWnd | IntPtr |
Returns
Type | Description |
---|---|
System.Boolean | true if it worked |