C# 识别屏幕数量?

发布于 2024-09-24 18:17:39 字数 114 浏览 1 评论 0原文

如何在 C# 中使用一个函数来运行窗口识别,该函数将在屏幕上显示数字 1、2...,就像我们右键单击屏幕(属性)然后转到“屏幕分辨率”和单击“识别”即可显示数字。

我们可以在 C# 中做到这一点吗?

How to have a function in C# to run the window identification, which will show the numbers 1, 2, ... on the screen same way as we do it by right click on the screen (properties) then we go to Screen Resolution and show the numbers by clicking on Identify.

Can we do that in C#?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏花。依旧 2024-10-01 18:17:39

是的,查看 Screen 类: http://msdn .microsoft.com/en-us/library/system.windows.forms.screen.aspx

您可以通过Screen.AllScreens获取所有屏幕的列表。

Yes, look at the Screen class: http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.aspx

You can get a list of all screens through Screen.AllScreens.

自找没趣 2024-10-01 18:17:39
foreach(var screen in System.Windows.Forms.Screen.AllScreens)
{
   string display_number = Regex.Match(screen.DeviceName,@"\d+").Value;
   Console.WriteLine($"Display Number = {display_number} isPrimary= {screen.Primary}");
}

输出:

Display Number = 1 isPrimary= False
Display Number = 2 isPrimary= True
Display Number = 3 isPrimary= False
foreach(var screen in System.Windows.Forms.Screen.AllScreens)
{
   string display_number = Regex.Match(screen.DeviceName,@"\d+").Value;
   Console.WriteLine(
quot;Display Number = {display_number} isPrimary= {screen.Primary}");
}

Output:

Display Number = 1 isPrimary= False
Display Number = 2 isPrimary= True
Display Number = 3 isPrimary= False
爱人如己 2024-10-01 18:17:39

使用 Screen.AllScreens 属性确实获取了附加到系统的监视器的数组。

然后 Screen.DeviceName属性会给你它的名字。然而,这可能与 MSDN 警告的数字不同:

该字符串可能包含不可打印的字符。

我会先检查一下,看看这是否满足您的需要。

Using the Screen.AllScreens Property does get an array of the monitors attached to the system.

Then Screen.DeviceName Property will give you it's name. However, that might not be the same as the number as the MSDN warns:

This string may contain non-printable characters.

I'd check this first to see if this gives you what you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文