I'm running a .NET desktop app in Per-Monitor v2 DPI Aware mode. Painting WinForms parts of the UI correctly requires that all painters know the current DPI value. High-level painters can get it from the HWND
, that's a working solution. However, lower level painters only have a GDI+ System.Drawing.Graphics
object.
I'm struggling with making System.Drawing.Graphics
tell the correct DPI. Now I'm seeing the SYSTEM-level DPI on it regardless of the current DPI of its HWND
. Its DpiX
/DpiY
properties are read-only, so they have to be affected indirectly.
Graphics
has two basic ways of how it can be created for a control, either with its HWND
, or an HDC
over it (which might be coming from ::GetDC
or ::BeginPaint
or even WM_PAINT
args). Either way it only has the SYSTEM DPI value, and not the per-monitor aware one. It would probably work to make a Bitmap
, configure it appropriately and paint into that first, then blit onto the control, but that's not too neat nor optimal.
So: I'm seeing a good per-monitor-aware DPI for an HWND
of a WinForms control, I want to see the same nice value on the Graphics
object DpiX
/DpiY
properties over that control, is there a way?