winforms icon indicating copy to clipboard operation
winforms copied to clipboard

[Question/suggestion] Can System.Drawing.Graphics be PerMonitorV2 compatible?

Open kirsan31 opened this issue 1 year ago • 4 comments

Background and motivation

Currently in PerMonitorV2 apps after autoscaling happens (dpi changed) DpiX/DpiY from Graphics objects (for example from OnPaint(PaintEventArgs e)) still return starting values. This raises some questions (I found many similar questions, but no answers):

  • Is it only DpiX/DpiY properties problem and we still able to use these graphics objects normally (keeping in mind real dpi of course)? The fact that these objects continue to be used normally within Winforms gives me a certain optimism on this matter :)
    • If this is only DpiX/DpiY problem, then can we solve it - make them return real dpi?
    • If this is whole Graphics problem, then can we solve it - make Graphics compatible with PerMonitorV2?

kirsan31 avatar Sep 13 '24 11:09 kirsan31

@kirsan31 I don't think there is much we can do here other than document what this really does. There is no way to set the DPI in GDI+ and it is effectively hard coded to a static that is:

GetDeviceCaps(CreateICA("DISPLAY", NULL, NULL, NULL, LOGPIXELSX);

JeremyKuhne avatar Sep 18 '24 17:09 JeremyKuhne

@JeremyKuhne

Really GdipGetDpiX the same as GetDeviceCaps(CreateICA("DISPLAY", NULL, NULL, NULL, LOGPIXELSX)?

I don't think there is much we can do here other than document what this really does.

I think yes to edit docs a bit will be helpful.

Do you think it would be appropriate to add new properties to the Graphics that return the real DPI for PerMonitorV2?

kirsan31 avatar Sep 20 '24 09:09 kirsan31

Really GdipGetDpiX the same as GetDeviceCaps(CreateICA("DISPLAY", NULL, NULL, NULL, LOGPIXELSX)?

Yep.

Do you think it would be appropriate to add new properties to the Graphics that return the real DPI for PerMonitorV2?

It might be misleading as I believe the current DPI setting actually impacts rendering. I'd have to dig into where the setting is used internally.

JeremyKuhne avatar Sep 20 '24 17:09 JeremyKuhne

It might be misleading as I believe the current DPI setting actually impacts rendering.

It was my main question. Currently my thoughts are - if they were involved in rendering, how then we would be able to draw windows correctly in PerMonitorV2 applications?

kirsan31 avatar Sep 20 '24 18:09 kirsan31