I have a window in my application that should only get dragged when the mouse has moved a certain distance. I want this distance to be the same as Windows default, but it seems to be 4 regardless of the DPI scaling of my monitor. Do I have to scale the value 4, or is it in fact DPI-aware?
I'm doing the following to check whether I should start dragging or not:
private static bool HasMouseMovedFarEnough(MouseEventArgs e)
{
Debug.Assert(_startPoint != null);
Vector delta = _startPoint.Value - e.GetPosition(null);
return Math.Abs(delta.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(delta.Y) > SystemParameters.MinimumVerticalDragDistance;
}
If you buy a 1080x1920 monitor in the shop, it will always tell you this size, and there might be functions that report scaled sized to you, but the size in Pixel will always be unscaled. That's the definition of a Pixel.
If you look in the SourceCode
_minimumHorizontalDragDistance =
SystemParameters.ConvertPixel(UnsafeNativeMethods.GetSystemMetrics(SM.CXDRAG))
And if you look in the Win32-API
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmetrics
The number of pixels on either side of a mouse-down point that the mouse pointer can move before a drag operation begins. This allows the user to click and release the mouse button easily without unintentionally starting a drag operation. If this value is negative, it is subtracted from the left of the mouse-down point and added to the right of it.
It says clearly, it's in Pixels. So as higher the resolution, as finer a user can adjust things. If you would scale it, the user would have no use of a higher resolution.