如何使用 C# 获取显示器支持的最大屏幕分辨率 [英] How to obtain the maximum screen resolution that a monitor supports using C#

查看:109
本文介绍了如何使用 C# 获取显示器支持的最大屏幕分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获得显示器支持的最大屏幕分辨率,而不是当前的分辨率,这很容易.任何帮助将不胜感激.

I need to obtain the Maximum supported screen resolution of a monitor, not the current resolution which is easy. Any help would be appreciated.

这是对我有用的更新后的解决方案.

        public Size GetMaximumScreenSizePrimary()
        {
            var scope = new System.Management.ManagementScope();
            var q = new System.Management.ObjectQuery("SELECT * FROM CIM_VideoControllerResolution");

            using (var searcher = new System.Management.ManagementObjectSearcher(scope, q))
            {
                var results = searcher.Get();
                UInt32 maxHResolution = 0;
                UInt32 maxVResolution = 0;

                foreach (var item in results)
                {
                    if ((UInt32)item["HorizontalResolution"] > maxHResolution)
                        maxHResolution = (UInt32)item["HorizontalResolution"];

                    if ((UInt32)item["VerticalResolution"] > maxVResolution)
                        maxVResolution = (UInt32)item["VerticalResolution"];
                }

                log.Debug("Max Supported Resolution " + maxHResolution + "x" + maxVResolution);
            }
            return new Size(maxHResolution, maxVResolution);
        }

推荐答案

从管理范围获取结果.

            var scope = new System.Management.ManagementScope();
            var q = new System.Management.ObjectQuery("SELECT * FROM CIM_VideoControllerResolution");

            using (var searcher = new System.Management.ManagementObjectSearcher(scope, q))
            {
                var results = searcher.Get();
                foreach (var item in results)
                {
                    Console.WriteLine(item["Caption"]);
                }
            }

有关可用信息的详细信息,请参阅CIM_VideoControllerResolution 页面.

For more information about what information is available, refer to the CIM_VideoControllerResolution page.

这篇关于如何使用 C# 获取显示器支持的最大屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆