c#多显分辨率测试

CONFIG 文件:

\\.\DISPLAY1,1920*1080
\\.\DISPLAY2,1920*1080
\\.\DISPLAY3,1920*1080

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management;
using Microsoft.Win32;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Drawing;
using System.Collections;

namespace Split_Screen_Detection_Resolution
{
    public partial class Split_Screen_Detection_Resolution : Form
    {
        public List<String> DisplayDevice_Resolution_Ratio;//分辨率信息;
        public List<Boolean> DisplayDevice_Resolution_State;//显示状态
        public List<String> Config_Info;//读取配置信息
        public List<String> Display_Resolution_Ratio_Management;
        public Split_Screen_Detection_Resolution()
        {
            InitializeComponent();
        }

        public Boolean ReadCfgInfo()//读取配置信息
        {
            Boolean Flag = false;
            Config_Info = new List<String>();
            FileStream fs = new FileStream("Split_Screen_Detection_Resolution.config", FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(fs, Encoding.Default);
            try
            {
                String Temp = String.Empty;
                while ((Temp = sr.ReadLine()) != null)
                {
                    Config_Info.Add(Temp);
                }
                Flag = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Flag = false;
            }
            finally
            {
                sr.Close();
                fs.Close();
            }
            return Flag;
        }
        public Boolean ReadDisplayDevice_Set_Sorte_screen()//采用screen读取分辨率
        {
            Boolean Flag = false;
            DisplayDevice_Resolution_Ratio = new List<string>();
            DisplayDevice_Resolution_Ratio.Clear();
            try
            {
                foreach (var screen in Screen.AllScreens)
                {
                    DisplayDevice_Resolution_Ratio.Add(screen.DeviceName + "," + screen.Bounds.Width.ToString() + "*" + screen.Bounds.Height.ToString());
                } 
                Flag = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,"系统提醒",MessageBoxButtons.OK,MessageBoxIcon.Error);
                Flag = false;
            }
            return Flag;
        }

        public Boolean ReadDisplayDevice_Set_Sorte_Management()
        {
            Boolean Flag = false;
            try
            {
                Display_Resolution_Ratio_Management = new List<string>();
                SelectQuery query = new SelectQuery("Select * from Win32_DesktopMonitor");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
                foreach (ManagementBaseObject display in searcher.Get())
                {
                    String ss = String.Empty;
                    if (display["ScreenHeight"].ToString().Trim() != String.Empty || display["ScreenHeight"].ToString().Trim() != null)
                        ss = display["ScreenHeight"].ToString().Trim();
                    else
                        ss = "null";
                    if (display["ScreenWidth"].ToString().Trim() != String.Empty || display["ScreenWidth"].ToString().Trim() != null)
                        ss += @"*" + display["ScreenWidth"].ToString().Trim();
                    else
                        ss += @"*" + "null";
                    MessageBox.Show(ss);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,"系统提醒",MessageBoxButtons.OK,MessageBoxIcon.Error);
                Flag = false;
            }
            return Flag;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            if (!ReadCfgInfo())
            {
                System.Environment.Exit(1);
            }
            DisplayDevice_Resolution_State = new List<bool>();
            DisplayDevice_Resolution_State.Add(false);
            DisplayDevice_Resolution_State.Add(false);
            DisplayDevice_Resolution_State.Add(false);
        }

        public void Create_New_Table()//清空所有多余空间内容
        {
            foreach (Control ss in this.Controls)
            {
                if (ss.Name.ToString() == "groupBox1")
                {
                    foreach (Control s in ss.Controls)
                    {
                        if(s.GetType().ToString() == "System.Windows.Forms.Label")
                        {
                            s.Text = "N/A";
                        }
                    }
                }
            }
            label1.Visible = false;
            label2.Text = "接口信息";
            label3.Text = "分辨率";
            label4.Text = "测试结果";
            DisplayDevice_Resolution_State = new List<bool>();
            DisplayDevice_Resolution_State.Add(false);
            DisplayDevice_Resolution_State.Add(false);
            DisplayDevice_Resolution_State.Add(false);

        }

        public Boolean ShowResult(Label Item1, Label Item2, Label Item3,String Config_Str)//显示测试结果
        {
            Boolean Flag = false;
            try
            {
                Boolean IsResult=false;
                int n=0;
                String[] Array_Str = Config_Str.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                foreach(String ss in DisplayDevice_Resolution_Ratio)
                {
                    String[] Array_ss = ss.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    if (DisplayDevice_Resolution_State[n] == false)
                    {
                        if (Array_Str[1] == Array_ss[1])
                        //if (ss == Config_Str)
                        {
                            IsResult = true;
                            DisplayDevice_Resolution_State[n] = true;
                            break;
                        }
                    }
                    n++;
                }
                Item1.Text = Array_Str[0].Trim();
                Item2.Text = Array_Str[1].Trim();
                if (IsResult)
                {
                    Flag = true;
                    Item3.BackColor = Color.Green;
                    Item3.Text = "PASS";
                }
                else
                {
                    Item3.BackColor = Color.Red;
                    Item3.Text = "Fail";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,"系统提醒",MessageBoxButtons.OK,MessageBoxIcon.Error);
                Flag = false;
            }
            return Flag;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Create_New_Table();
            Boolean TestResult=false;
            if (ReadDisplayDevice_Set_Sorte_screen())
            {
                if (Config_Info.Count == 1)
                {
                    TestResult = (ShowResult(label5, label6, label7, Config_Info[0]));
                }
                else if (Config_Info.Count == 2)
                {
                    TestResult = (ShowResult(label5, label6, label7, Config_Info[0]) &&
                        ShowResult(label8, label9, label10, Config_Info[1]));
                }
                else if (Config_Info.Count == 3)
                {
                    TestResult = (ShowResult(label5, label6, label7, Config_Info[0]) &&
                    ShowResult(label8, label9, label10, Config_Info[1]) &&
                    ShowResult(label11, label12, label13, Config_Info[2]));
                }

                if (TestResult)
                {
                    label1.Visible = true;
                    label1.Text = "PASS";
                    label1.ForeColor = Color.Green;
                    System.Environment.Exit(0);
                    //timer1.Enabled = true;
                }
                else
                {
                    label1.Visible = true;
                    label1.Text = "FAIL";
                    label1.ForeColor = Color.Red;
                }
            }
            else
            {
                label1.Visible = true;
                label1.Text = "FAIL";
                label1.ForeColor = Color.Red;
            }
        }

        public int i=2;
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (i == 0)
                System.Environment.Exit(0);
            i--;
        }

        private void Split_Screen_Detection_Resolution_FormClosed(object sender, FormClosedEventArgs e)         {             System.Environment.Exit(1);         }     } }