![]() ![]() Divide the Screen Heights to get the scaling factor and round it to two decimalsĭouble ScreenScalingFactor = Math. Int PhysicalScreenHeight = GetDeviceCaps(DeviceContextHandle, (int)DeviceCap.DESKTOPVERTRES) Int LogicalScreenHeight = GetDeviceCaps(DeviceContextHandle, (int)DeviceCap.VERTRES) Call GetDeviceCaps with the Handle to retrieve the Screen Height ![]() IntPtr DeviceContextHandle = GraphicsObject.GetHdc() Get Handle to the device context associated with this Graphics object Graphics GraphicsObject = Graphics.FromHwnd(IntPtr.Zero) ![]() Create Graphics object from the current windows handle Static double GetWindowsScreenScalingFactor(bool percentage = true) Public static extern int GetDeviceCaps(IntPtr hDC, int nIndex) Return GetDpiForWindow(windowHandle) / 96f įor this to work correctly on Windows 10 anniversary, you need to add an app.manifest to your C# project: Ī more complete version of Ric Gaudet's answer: Public float GetDisplayScaleFactor(IntPtr windowHandle) When it was launched in late 2019, the Surface Pro X offered a number of key advantages over Microsoft’s Intel-based Surface Pro models. For known issues that might affect your device, you can also check the Windows release health hub. Static extern int GetDpiForWindow(IntPtr hWnd) To check if Windows 11 is ready for your device, select Start > Settings > Update & Security > Windows Update > Check for updates. This is a very old question, but since Windows 8.1, one can use various other functions, like GetDpiForWindow do something nice for people who can't see very well. Int logpixelsy = GetDeviceCaps(desktop, (int)DeviceCap.LOGPIXELSY) įloat screenScalingFactor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight įloat dpiScalingFactor = (float)logpixelsy / (float)96 Int PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES) Int LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES) Static extern int GetDeviceCaps(IntPtr hdc, int nIndex) Īnd usage: Graphics g = Graphics.FromHwnd(IntPtr.Zero) Not sure why this is the case, but this code seems to work for any scale setting. I tested about 20 different scaling factors, and the DPI always returns as 96, except for when set at 125%, which returns a DPI of 120. Using Farshid T's answer as a base works in every scaling factor, except for 125%. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |