Windows 屏幕保护程序多显示器问题

发布于 2024-08-15 13:56:59 字数 1009 浏览 9 评论 0原文

我编写了一个简单的屏幕保护程序,已将其部署到我们公司的所有客户端 PC 上。

由于我们的大多数电脑都有双显示器,因此我注意确保屏幕保护程序在两个显示器上运行。

这工作正常,但是在某些系统上,主屏幕已交换(到左侧显示器),屏幕保护程序仅在左侧(主)屏幕上工作。

有问题的代码如下。任何人都可以看到我做错了什么,或者有更好的处理方法吗?

作为信息,“this”的上下文是屏幕保护程序表单本身。

// Make form full screen and on top of all other forms

int minY = 0;
int maxY = 0;
int maxX = 0;
int minX = 0;

foreach (Screen screen in Screen.AllScreens)
{
    // Find the bounds of all screens attached to the system

    if (screen.Bounds.Left < minX)
        minX = screen.Bounds.Left;

    if (screen.Bounds.Width > maxX)
        maxX = screen.Bounds.Width;

    if (screen.Bounds.Bottom < minY)
        minY = screen.Bounds.Bottom;

    if (screen.Bounds.Height > maxY)
        maxY = screen.Bounds.Height;
}

// Set the location and size of the form, so that it
// fills the bounds of all screens attached to the system

Location = new Point(minX, minY);
Height = maxY - minY;
Width = maxX - minX;
Cursor.Hide();
TopMost = true;

I have a simple screensaver that I've written, which has been deployed to all of our company's client PCs.

As most of our PCs have dual monitors, I took care to ensure that the screensaver ran on both displays.

This works fine, however on some systems, where the primary screen has been swapped (to the left monitor), the screensaver only works on the left (primary) screen.

The offending code is below. Can anyone see anything I've done wrong, or a better way of handling this?

For info, the context of "this", is the screensaver form itself.

// Make form full screen and on top of all other forms

int minY = 0;
int maxY = 0;
int maxX = 0;
int minX = 0;

foreach (Screen screen in Screen.AllScreens)
{
    // Find the bounds of all screens attached to the system

    if (screen.Bounds.Left < minX)
        minX = screen.Bounds.Left;

    if (screen.Bounds.Width > maxX)
        maxX = screen.Bounds.Width;

    if (screen.Bounds.Bottom < minY)
        minY = screen.Bounds.Bottom;

    if (screen.Bounds.Height > maxY)
        maxY = screen.Bounds.Height;
}

// Set the location and size of the form, so that it
// fills the bounds of all screens attached to the system

Location = new Point(minX, minY);
Height = maxY - minY;
Width = maxX - minX;
Cursor.Hide();
TopMost = true;

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

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

发布评论

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

评论(1

二智少女 2024-08-22 13:56:59

您想要检查 screen.Bounds.Right 而不是 screen.Bounds.Width。

对于身高也是如此。

You want to check screen.Bounds.Right rather than screen.Bounds.Width.

Similarly for height.

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