博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【语言-c#】计算电脑的屏幕尺寸
阅读量:2192 次
发布时间:2019-05-02

本文共 2192 字,大约阅读时间需要 7 分钟。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Runtime.InteropServices;using System.Drawing;namespace RSS_STAND_ALONE{    public class SystemInfo    {        public virtual List
GetMonitorPnpDeviceId() { List
rt = new List
(); using (System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_DesktopMonitor")) { using (System.Management.ManagementObjectCollection moc = mc.GetInstances()) { foreach (var o in moc) { var each = (System.Management.ManagementObject)o; object obj = each.Properties["PNPDeviceID"].Value; if (obj == null) continue; rt.Add(each.Properties["PNPDeviceID"].Value.ToString()); } } } return rt; } public virtual byte[] GetMonitorEdid(string monitorPnpDevId) { return (byte[])Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\" + monitorPnpDevId + @"\Device Parameters", "EDID", new byte[] { }); } //获取显示器物理尺寸(cm) public virtual SizeF GetMonitorPhysicalSize(string monitorPnpDevId) { byte[] edid = GetMonitorEdid(monitorPnpDevId); if (edid.Length < 23) return SizeF.Empty; return new SizeF(edid[21], edid[22]); } //通过屏显示器理尺寸转换为显示器大小(inch) public static float MonitorScaler(SizeF moniPhySize) { double mDSize = Math.Sqrt(Math.Pow(moniPhySize.Width, 2) + Math.Pow(moniPhySize.Height, 2)) / 2.54d; return (float)Math.Round(mDSize, 1); } public static void Debug() { SystemInfo sysInfo = new SystemInfo(); string id = sysInfo.GetMonitorPnpDeviceId()[0]; SizeF size = sysInfo.GetMonitorPhysicalSize(id); System.Windows.Forms. MessageBox.Show(SystemInfo.MonitorScaler(size).ToString() + @"寸"); } }}

 

转载地址:http://cljub.baihongyu.com/

你可能感兴趣的文章
作为一名软件测试工程师,需要具备哪些能力
查看>>
【Pyton】【小甲鱼】类和对象:一些相关的BIF(内置函数)
查看>>
【Pyton】【小甲鱼】魔法方法
查看>>
单元测试需要具备的技能和4大阶段的学习
查看>>
【Loadrunner】【浙江移动项目手写代码】代码备份
查看>>
Python几种并发实现方案的性能比较
查看>>
[Jmeter]jmeter之脚本录制与回放,优化(windows下的jmeter)
查看>>
Jmeter之正则
查看>>
【JMeter】1.9上考试jmeter测试调试
查看>>
【虫师】【selenium】参数化
查看>>
【Python练习】文件引用用户名密码登录系统
查看>>
学习网站汇总
查看>>
【Python】用Python打开csv和xml文件
查看>>
【Loadrunner】性能测试报告实战
查看>>
【自动化测试】自动化测试需要了解的的一些事情。
查看>>
【selenium】selenium ide的安装过程
查看>>
【手机自动化测试】monkey测试
查看>>
【英语】软件开发常用英语词汇
查看>>
Fiddler 抓包工具总结
查看>>
【雅思】雅思需要购买和准备的学习资料
查看>>