C# Get the system DPI scaling ratio and resolution size

C# Get the system DPI scaling ratio and resolution size

C# Get the system DPI scaling ratio and resolution size A solution to obtain the real desktop resolution when the desktop scaling ratio is not 100% General method System.Windows.Forms.Screen class // Get the current main screen resolution int screenWidth = Screen.PrimaryScreen.Bounds.Width; int screenHeight = Screen.PrimaryScreen.Bounds.Height; // Get the specified screen resolution Screen secondaryScreen = Screen.AllScreens[1]; int secondaryScreenWidth = secondaryScreen.Bounds.Width; int secondaryScreenHeight = secondaryScreen.Bounds.Height; System.Windows.SystemParameters class // Get the current main screen resolution double screenWidth = SystemParameters.PrimaryScreenWidth; double screenHeight = SystemParameters.PrimaryScreenHeight; // Get the resolution of all screens double virtualScreenWidth = SystemParameters.VirtualScreenWidth; double virtualScreenHeight = SystemParameters.VirtualScreenHeight; A virtual screen refers to a logical screen composed of all physical screens, which can be used to display applications across multiple physical screens. Both of these methods can obtain the screen resolution under normal circumstances – when the desktop scaling ratio is not 100%, the resolution obtained is ” “Real” resolution, but adjust the width and height of the content displayed on the screen according to the scaling ratio. Windows API At first I wrote a function that only gets the DPI scaling ratio, and then multiplied it manually. However, when I called System.Windows.Interop, I couldn’t find this namespace on my colleague’s computer. I…

C# Get the system DPI scaling ratio and resolution size

C# Get the system DPI scaling ratio and resolution size

C# Get the system DPI scaling ratio and resolution size A solution to obtain the real desktop resolution when the desktop scaling ratio is not 100% General method System.Windows.Forms.Screen class // Get the current main screen resolution int screenWidth = Screen.PrimaryScreen.Bounds.Width; int screenHeight = Screen.PrimaryScreen.Bounds.Height; // Get the specified screen resolution Screen secondaryScreen = Screen.AllScreens[1]; int secondaryScreenWidth = secondaryScreen.Bounds.Width; int secondaryScreenHeight = secondaryScreen.Bounds.Height; System.Windows.SystemParameters class // Get the current main screen resolution double screenWidth = SystemParameters.PrimaryScreenWidth; double screenHeight = SystemParameters.PrimaryScreenHeight; // Get the resolution of all screens double virtualScreenWidth = SystemParameters.VirtualScreenWidth; double virtualScreenHeight = SystemParameters.VirtualScreenHeight; A virtual screen refers to a logical screen composed of all physical screens, which can be used to display applications across multiple physical screens. Both of these methods can obtain the screen resolution under normal circumstances – when the desktop scaling ratio is not 100%, the resolution obtained is ” “Real” resolution, but adjust the width and height of the content displayed on the screen according to the scaling ratio. Windows API At first I wrote a function that only gets the DPI scaling ratio, and then multiplied it manually. However, when I called System.Windows.Interop, I couldn’t find this namespace on my colleague’s computer. I…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索