将表单扩展到所有屏幕

发布于 2024-09-25 10:49:25 字数 34 浏览 0 评论 0原文

问题很简单:有没有办法将单个表单扩展到所有连接的屏幕?

The question is simple: is there a way to expand a single form to all connected screens?

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

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

发布评论

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

评论(2

丢了幸福的猪 2024-10-02 10:49:25

不可以,除非您要使用相当低级的语言(例如 C)进行编码并获取对图形内存的访问权限。

一般来说,是操作系统为你执行布局,所以除非你有低级访问权限,或者有供应商发布的 API,否则我想这将是相当困难的。

No, unless you are going to code in a reasonably low-level language, such as C and grab access to graphics memory.

Generally it's the operating system that performs the layout for you, so unless you have low-level access, or API published by the vendor, it would be quite hard I guess.

风追烟花雨 2024-10-02 10:49:25

是的,所有屏幕构成了一个巨大的虚拟表面,您可以在上面放置表单。您只需将表单的位置设置为该表面的左上角,并将其大小设置为该表面的大小。

您可以使用以下代码找到该表面的范围:

private static Rectangle GetVirtualDisplayBounds()
{
    Screen[] allScreens = Screen.AllScreens;

    Point topLeft = allScreens[0].Bounds.Location;
    Point bottomRight = topLeft + allScreens[0].Bounds.Size;

    foreach (Screen screen in allScreens.Skip(1))
    {
        topLeft = new Point(Math.Min(topLeft.X, screen.Bounds.X),
                            Math.Min(topLeft.Y, screen.Bounds.Y));

        bottomRight = new Point(Math.Max(bottomRight.X, screen.Bounds.Right),
                                Math.Max(bottomRight.Y, screen.Bounds.Bottom));
    }

    return new Rectangle(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y);
}

然后您可以适当调整表单的大小:

var bounds = GetVirtualDisplayBounds();
form.Location = bounds.Location;
form.Size = bounds.Size;

您可能还想禁用表单边框:

form.FormBorderStyle = FormBorderStyle.None;

不过我注意到,当您显示表单时,它会弹出到 0 的位置,0,这意味着如果您有任何监视器位于该点的上方或左侧,它们将不会被覆盖。要解决此问题,您需要在表单显示后设置位置。

Yes, all of the screens make up a giant virtual surface upon which you can place your form. You need to merely set the form's location to the top-left of this surface and its size to the size of this surface.

You can find the extent of this surface with the following code:

private static Rectangle GetVirtualDisplayBounds()
{
    Screen[] allScreens = Screen.AllScreens;

    Point topLeft = allScreens[0].Bounds.Location;
    Point bottomRight = topLeft + allScreens[0].Bounds.Size;

    foreach (Screen screen in allScreens.Skip(1))
    {
        topLeft = new Point(Math.Min(topLeft.X, screen.Bounds.X),
                            Math.Min(topLeft.Y, screen.Bounds.Y));

        bottomRight = new Point(Math.Max(bottomRight.X, screen.Bounds.Right),
                                Math.Max(bottomRight.Y, screen.Bounds.Bottom));
    }

    return new Rectangle(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y);
}

Then you can size your form appropriately:

var bounds = GetVirtualDisplayBounds();
form.Location = bounds.Location;
form.Size = bounds.Size;

You may also want to disable form borders:

form.FormBorderStyle = FormBorderStyle.None;

I have noticed though, that when you show your form it will pop back to a location of 0,0, which means that if you have any monitors positioned above or to the left of this point they will not be covered. To solve this you need to set the location after the form is shown.

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