![]() ![]() 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) Static extern int GetDpiForWindow(IntPtr hWnd) ![]() 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 |