在C#中,要處理多顯示器,可以使用System.Windows.Forms.Screen
類
using System;
using System.Windows.Forms;
namespace MultipleMonitorsExample
{
class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// 獲取所有顯示器
Screen[] screens = Screen.AllScreens;
// 遍歷所有顯示器并顯示它們的信息
foreach (Screen screen in screens)
{
Console.WriteLine($"Screen: {screen.DeviceName}");
Console.WriteLine($"Bounds: {screen.Bounds}");
Console.WriteLine($"Working Area: {screen.WorkingArea}");
Console.WriteLine();
}
Console.ReadKey();
}
}
}
這個示例將輸出所有連接的顯示器的信息,包括設備名稱、邊界和工作區域。你可以根據需要修改代碼以滿足你的需求。