【发布时间】:2011-06-16 09:46:06
【问题描述】:
可能重复:
How do I determine the true pixel size of my Monitor in .NET?
如何获得显示器尺寸我的意思是它的物理尺寸如何宽度和高度以及对角线例如17英寸或什么
我不需要分辨率,我试过了
using System.Management ;
namespace testscreensize
{
class Program
{
static void Main(string[] args)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("\\root\\wmi", "SELECT * FROM WmiMonitorBasicDisplayParams");
foreach (ManagementObject mo in searcher.Get())
{
double width = (byte)mo["MaxHorizontalImageSize"] / 2.54;
double height = (byte)mo["MaxVerticalImageSize"] / 2.54;
double diagonal = Math.Sqrt(width * width + height * height);
Console.WriteLine("Width {0:F2}, Height {1:F2} and Diagonal {2:F2} inches", width, height, diagonal);
}
Console.ReadKey();
}
}
}
报错
找不到类型或命名空间名称'ManagementObjectSearcher'
它仅适用于 vista,我需要更广泛的解决方案
我也试过了
Screen.PrimaryScreen.Bounds.Height
但它会返回分辨率
【问题讨论】:
-
GetDeviceCaps 可能会有所帮助。见msdn.microsoft.com/en-us/library/dd144877(v=vs.85).aspx
-
像素和显示器的真实尺寸完全不同,