C # Use the WMI Object to obtain the system DPI.

Source: Internet
Author: User

Before using the WMI object, you must add a reference to System. Management, and then you can call the WMI Object.
The WMI object we use is: win32_shorttopmonitor.
Object Reference: http://msdn.microsoft.com/zh-cn/library/Aa394122
Code:
Static void Main (string [] args ){

Using (ManagementClass mc = new ManagementClass ("Win32_DesktopMonitor ")){
Using (ManagementObjectCollection moc = mc. GetInstances ()){

Int PixelsPerXLogicalInch = 0; // dpi for x
Int PixelsPerYLogicalInch = 0; // dpi for y

Foreach (ManagementObject each in moc ){
PixelsPerXLogicalInch = int. Parse (each. Properties ["PixelsPerXLogicalInch"]. Value. ToString ()));
PixelsPerYLogicalInch = int. Parse (each. Properties ["PixelsPerYLogicalInch"]. Value. ToString ()));
}

Console. WriteLine ("PixelsPerXLogicalInch:" + PixelsPerXLogicalInch. ToString ());
Console. WriteLine ("PixelsPerYLogicalInch:" + PixelsPerYLogicalInch. ToString ());
Console. Read ();
}

}
}

The above code passes the test in WIN7 environment.

 

From the white ocean

Related Article

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.