C # Gets the current screen dpi

Source: Internet
Author: User

Original: C # gets the current screen dpi

1. Get through the Graphics class

Graphics currentgraphics = Graphics.fromhwnd (new  windowinterophelper (MainWindow). Handle); double dpixratio = currentgraphics.dpix/;

For example, the current screen setting dpi setting 1.5 times times, can be obtained through the background as above.

2. By Win32-managementclass

using(ManagementClass MC =NewManagementClass ("Win32_DesktopMonitor")){    using(Managementobjectcollection MOC =MC. GetInstances ()) {intPixelsperxlogicalinch =0;//dpi for x        intPixelsperylogicalinch =0;//dpi for y        foreach(ManagementObject eachinchMOC) {Pixelsperxlogicalinch=int. Parse (each. properties["Pixelsperxlogicalinch"].            Value.tostring ())); Pixelsperylogicalinch=int. Parse (each. properties["Pixelsperylogicalinch"].        Value.tostring ())); }    }}

It is worth mentioning that, with the main screen in the case, is not able to get the dpi of the secondary screen!

Note: Physical resolution/real resolution/aspect scaling of the screen, refer to C # API for system DPI zoom and resolution size

C # Gets the current screen dpi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.