WPF-屏幕ID在重新启动后更改,获得正确的ID。 [英] WPF- screen Id changes after reboot , get right Id.

查看:81
本文介绍了WPF-屏幕ID在重新启动后更改,获得正确的ID。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个wpf应用程序,我在多个监视器中显示多个窗口。



I have a wpf app and I was displaying multiple windows into multiple monitors.

/// <summary>
      /// Display the panels received as a parameter over the screen fixe by static coordinates
      /// </summary>
      /// <param name="panel"></param>
      public static void ShowByCoordinates(Window window, int screenId, int LeftTransform, int TopTransform)
      {
          System.Drawing.Rectangle bounds = System.Drawing.Rectangle.Empty;
          System.Windows.Forms.Screen s0 = System.Windows.Forms.Screen.AllScreens[screenId];
          bounds = s0.WorkingArea;
          window.Left = bounds.X + LeftTransform;
          window.Top = bounds.Y + TopTransform;
          window.Show();

      }









那个屏幕id参数是从app.config文件中获取的。问题是如果重置电脑,那些监视器/电视会改变它们的ID。我找不到从监视器获取固定标识符并将其转换为可以显示我的窗口的屏幕的好方法。我看看如何获​​得监视器







that screen id parameter was get it from app.config file. Problem is those monitors/tvs change their ids if the pc is reset. I could not find a good way to get fixed identifiers from the monitors and convert them into screens where my windows can be displayed. I have look how to get monitors with

<pre lang="C#">
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DesktopMonitor");Console.WriteLine(&quot;PNP Device ID: {0}&quot;, obj[&quot;PNPDeviceID&quot;]);





但我不知道如何将它们转换成屏幕或者用什么属性来指向它们。任何帮助都会非常感激。



but I dont know how to convert them into screen or what property use to point them always.Any help would be very appreciate it.

推荐答案

你在叫什么屏幕ID只是数组中屏幕的索引。你不能依靠它来识别屏幕。



使用 DeviceName 属性 [ ^ ]:

What you're calling "screen ID" is just the index of the screen within the array. You can't rely on it to identify the screen.

You'd probably have better luck using the DeviceName property[^]:
public static void ShowByCoordinates(Window window, string screenName, int LeftTransform, int TopTransform)
{
    Screen s0 = Screen.AllScreens.FirstOrDefault(s => s.DeviceName == screenName) ?? Sreen.PrimaryScreen;
    Rectangle bounds = s0.WorkingArea;
    window.Left = bounds.X + LeftTransform;
    window.Top = bounds.Y + TopTransform;
    window.Show();
}


这篇关于WPF-屏幕ID在重新启动后更改,获得正确的ID。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆