how get dpi scale factor
-
Where are you going to get it from?
-
var graphics = control.CreateGraphics()) int dpi_scale_val= graphics.DpiX; but it always return 96
-
If you want help with a programming question, you really need to provide proper details, rather than vague statements.
-
"200%" is not a resolution. It's a scaling factor used to enlarge text when displayed. The display dpi is still 96. One has nothing to do with the other.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
"200%" is not a resolution. It's a scaling factor used to enlarge text when displayed. The display dpi is still 96. One has nothing to do with the other.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
DPI scaling is not that simple. Here's how I do it for WinForms apps: First, your app needs to be DPI-aware. You set that by the manifest. You also set that with with the AutoScaleDimensions and AutoScaleMode properties on each form. Second, if you're designing forms from within Visual Studio, you need to do it on a system that is using 100% as the scaling factor for the display. If you don't do this, step 3 doesn't work. Third, you can now use
scaleFrom96 = this.DeviceDpi / 96.0
to calculate a multiplication factor for resizing those things manually that WinForms will not do for you. Be warned, it is very hit and miss what things will be scaled for you automatically and what things will not. Lots of testing required. OR you punt it all and design on a system that matches the system the app will be running on. Judy
Be wary of strong drink. It can make you shoot at tax collectors - and miss. Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
-
OK, what for?
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
DPI scaling is not that simple. Here's how I do it for WinForms apps: First, your app needs to be DPI-aware. You set that by the manifest. You also set that with with the AutoScaleDimensions and AutoScaleMode properties on each form. Second, if you're designing forms from within Visual Studio, you need to do it on a system that is using 100% as the scaling factor for the display. If you don't do this, step 3 doesn't work. Third, you can now use
scaleFrom96 = this.DeviceDpi / 96.0
to calculate a multiplication factor for resizing those things manually that WinForms will not do for you. Be warned, it is very hit and miss what things will be scaled for you automatically and what things will not. Lots of testing required. OR you punt it all and design on a system that matches the system the app will be running on. Judy
Be wary of strong drink. It can make you shoot at tax collectors - and miss. Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
Judy, Great answer, I hope to see you answering more C# related questions in the future. :) The Windows API equivalent to what you are doing there would be calling the GetDpiForMonitor function[^] and obtaining the MDT_EFFECTIVE_DPI[^] value and dividing by the system default. Of course the operating system hides dpi/scaling values from threads unless it's DPI aware[^]. So the caller needs to set thread DPI awareness before performing the calculation. I'd like to add that GetScaleFactorForMonitor[^] may return incorrect values. The manual calculation is preferred. I'd also like to add that the process doesn't necessarily need to be DPI aware. Beginning with Win10 1607 you can create a DPI aware thread to get those values by using the SetThreadDpiAwarenessContext function[^]. Hope to see you answering more often! Best Wishes, -David Delaune