给定屏幕的有效分辨率列表?

发布于 2024-08-06 16:14:40 字数 158 浏览 5 评论 0原文

有没有办法获得给定屏幕的所有有效分辨率?

我目前有一个填充了所有有效屏​​幕的下拉菜单(使用Screen.AllScreens)。当用户选择一个屏幕时,我想向他们展示第二个下拉列表,列出该显示器的所有有效分辨率(不仅仅是当前分辨率)。

Is there a way to get ALL valid resolutions for a given screen?

I currently have a dropdown that is populated with all valid screens (using Screen.AllScreens). When the user selects a screen, I'd like to present them with a second dropdown listing all valid resolutions for that display (not just the current resolution).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小霸王臭丫头 2024-08-13 16:14:40

我认为应该可以使用 Windows Management Instrumentation (WMI) 获取信息。可以使用其中的类从 .NET 访问 WMI System.Management 命名空间。

解决方案将类似于以下内容。我不太了解 WMI,无法立即找到您要查找的信息,但我找到了显卡支持的分辨率的 WMI 类。该代码需要引用 System.Management.dll 并导入 System.Management 命名空间。

var scope = new ManagementScope();

var query = new ObjectQuery("SELECT * FROM CIM_VideoControllerResolution");

using (var searcher = new ManagementObjectSearcher(scope, query))
{
    var results = searcher.Get();

    foreach (var result in results)
    {
        Console.WriteLine(
            "caption={0}, description={1} resolution={2}x{3} " +
            "colors={4} refresh rate={5}|{6}|{7} scan mode={8}",
            result["Caption"], result["Description"],
            result["HorizontalResolution"],
            result["VerticalResolution"],
            result["NumberOfColors"],
            result["MinRefreshRate"],
            result["RefreshRate"],
            result["MaxRefreshRate"],
            result["ScanMode"]);
    }
}

I think it should be possible to get the information using Windows Management Instrumentation (WMI). WMI is accessible from .NET using the classes from them System.Management namespace.

A solution will look similar to the following. I don't know WMI well and could not immediately find the information you are looking for, but I found the WMI class for the resolutions supported by the video card. The code requires referencing System.Management.dll and importing the System.Management namespace.

var scope = new ManagementScope();

var query = new ObjectQuery("SELECT * FROM CIM_VideoControllerResolution");

using (var searcher = new ManagementObjectSearcher(scope, query))
{
    var results = searcher.Get();

    foreach (var result in results)
    {
        Console.WriteLine(
            "caption={0}, description={1} resolution={2}x{3} " +
            "colors={4} refresh rate={5}|{6}|{7} scan mode={8}",
            result["Caption"], result["Description"],
            result["HorizontalResolution"],
            result["VerticalResolution"],
            result["NumberOfColors"],
            result["MinRefreshRate"],
            result["RefreshRate"],
            result["MaxRefreshRate"],
            result["ScanMode"]);
    }
}
青瓷清茶倾城歌 2024-08-13 16:14:40

以下链接包含详细的代码示例:

任务 2:更改显示分辨率
http://msdn.microsoft.com/en -us/library/aa719104(VS.71).aspx#docum_topic2

The following link contains detailed code examples for this:

Task 2: Changing the Display Resolution
http://msdn.microsoft.com/en-us/library/aa719104(VS.71).aspx#docum_topic2

静水深流 2024-08-13 16:14:40

接受的答案似乎不适用于 Windows 8.1,至少在我的机器上。查询运行正常,但结果中有 0 个条目。考虑到 Bijoy K Jose 的评论,我想我不是唯一的一个。

然而,以下问题的经过验证的答案效果很好:
如何使用 C# 列出可用的视频模式?

感谢 Vimvq1987

The accepted answer doesn't seem to work on Windows 8.1, at least on my machine. The query runs fine but there are 0 entries in the results. And considering Bijoy K Jose's comment I suppose that I am not the only one.

However the validated answer for the following question worked out just fine :
How to list available video modes using C#?

Thanks to Vimvq1987

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文