Open
Description
Description
When display setting is changed or display scale(dpi) is changed while the application is running, SystemParameters.WorkArea
does not return proper value.
If you programatically change Top or Left property of Window that are relative to WorkArea.Width
/WorkArea.Height
, position of the Window would be absurd.
Width and Height are scaled without any problem. they will be just bigger and smaller to display ratio.
Reproduction Steps
- Build app with PerMonitorV2 enabled.
- Run app with 100% or 150% display scale ratio.
- Change display scale ratio 100% to 150% or 150% to 100%.
- Change Window's Top or Left property programatically that are relative to WorkArea's value. (i.e. right bottom corner or work area)
- voilà!
Expected behavior
SystemParameters.WorkArea returns proper value.
Actual behavior
awkwardly scaled RECT is returned.
Regression?
I only tested on .net framework environment that supports PerMonitorV2.
Known Workarounds
- Use same API that SystemParameters.WorkArea uses.
SystemParametersInfo
SystemParameters(SPI_GETWORKAREA, 0, ref RECT, 0)
- Get current display scale with
VisualTreeHelper.GetDpi()
orDpiChanged
event. - adjust value of returned
RECT
fromSystemParameters()
withDpiScale
instance. RECT.Left
/RECT.Right
will be divided withDpiScale.DpiScaleX
andRECT.Top
/RECT.Bottom
will be divided withDpiScale.DpiScaleY
- divided values are correct WorkArea information.
Impact
No response
Configuration
- .NET framework (4.7.2, 4.8.1)
- Windows 10/11 (x64)
- AnyCPU builds
Other information
No response