温馨提示×

c# enumdisplaymonitors如何处理显示器配置

c#
小樊
87
2024-12-07 19:05:49
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在C#中,要处理显示器配置并显示相关信息,可以使用System.Windows.Forms.Screen类。以下是一个示例代码,展示了如何获取显示器分辨率、工作区大小以及可用屏幕区域等信息:

using System;
using System.Windows.Forms;

namespace EnumDisplayMonitors
{
    class Program
    {
        [STAThread]
        static void Main()
        {
            // 获取所有显示器
            Screen[] screens = Screen.AllScreens;

            // 遍历所有显示器
            foreach (Screen screen in screens)
            {
                // 获取显示器的分辨率
                Rectangle bounds = screen.Bounds;
                int width = bounds.Width;
                int height = bounds.Height;

                // 获取显示器的工作区大小
                Rectangle workingArea = screen.WorkingArea;
                int workingWidth = workingArea.Width;
                int workingHeight = workingArea.Height;

                // 获取显示器的可用屏幕区域
                Rectangle available = screen.Available;
                int availableWidth = available.Width;
                int availableHeight = available.Height;

                // 输出显示器信息
                Console.WriteLine($"Monitor: {screen.DeviceName}");
                Console.WriteLine($"Resolution: {width}x{height}");
                Console.WriteLine($"Working Area: {workingWidth}x{workingHeight}");
                Console.WriteLine($"Available Area: {availableWidth}x{availableHeight}");
                Console.WriteLine();
            }
        }
    }
}

这个示例代码首先获取所有显示器,然后遍历每个显示器,获取其分辨率、工作区大小和可用屏幕区域等信息,并将这些信息输出到控制台。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:c# enumdisplaymonitors有哪些应用

0