【问题标题】:How can i detect to what source my monitor is set to now?我如何检测我的显示器现在设置的来源?
【发布时间】:2016-02-14 12:58:30
【问题描述】:

现在我的显示器设置为 DVI-D,我知道这是我的电脑。 但例如我的 playstation 4 连接到 HDMI 1 我想要做的是当我将显示器源更改为 HDMI 1 时检测它,当我将其更改回 DVI-D 时检测它,这样我就可以知道我的显示器源何时在 pc 或 ps4 上。

到目前为止我尝试的是这个。 我在我的设计器中添加了一个计时器,我将计时器运行了 40 秒,并在计时器中调用了一个方法:

int counttimer2 = 0;
    private void timer2_Tick(object sender, EventArgs e)
    {
        if (counttimer2 == 40)
        {
            w.Close();
            timer2.Stop();
        }
        DetectScreenName();
        counttimer2 += 1;
    }

还有 DetectScreenName 方法:

private void DetectScreenName()
        {
            if (counttimer2 < 40)
            {
                SelectQuery q = new SelectQuery("SELECT Name, DeviceID, Description FROM Win32_DesktopMonitor");
                using (ManagementObjectSearcher mos = new ManagementObjectSearcher(q))
                {
                    foreach (ManagementObject mo in mos.Get())
                    {
                        Console.WriteLine("{0}, {1}, {2}",
                            mo.Properties["Name"].Value.ToString(),
                            mo.Properties["DeviceID"].Value.ToString(),
                            mo.Properties["Description"].Value.ToString());
                        results.Add(mo.Properties["Name"].Value.ToString());
                        results.Add(mo.Properties["DeviceID"].Value.ToString());
                        results.Add(mo.Properties["Description"].Value.ToString());
                        w.WriteLine(mo.Properties["Name"].Value.ToString());
                        w.WriteLine(mo.Properties["DeviceID"].Value.ToString());
                        w.WriteLine(mo.Properties["Description"].Value.ToString());
                    }
                }
            }
        }

在我正在写结果的文本文件上查看更改,所有结果都是相同的:

通用 PnP 监视器 桌面监视器1 通用 PnP 监视器

我看到的每一秒:

通用 PnP 监视器 桌面监视器1 通用 PnP 监视器

当我将监视器源切换到 HDMI 1 时它没有改变

【问题讨论】:

    标签: c# .net winforms generics


    【解决方案1】:

    当您切换显示器的信号源时,对于您的计算机而言,没有任何变化 - 就好像显示器已关闭。

    很遗憾,您无法可靠地检测到这一点,如 Is there any way to detect the monitor state in Windows (on or off)?Detect external display being connected or removed under Windows 7 中所述。

    【讨论】:

      猜你喜欢
      • 2010-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多