首页 > 解决方案 > 带有表单和面板的 MultiMonitor

问题描述

我有 3 台显示器连接。我想用表单覆盖整个 3 个屏幕,我想在主屏幕的中心显示面板。我该怎么做?

现在我已经用这段代码覆盖了每个屏幕。

int form_width = 0;
        int form_height = 0;
        int form_x = 0;
        int form_y = 0;
        int sub_screen_width = 0;
        int sub_screen_height = 0;

        bool minus_x = false;
        bool minus_y = false;

        foreach (Screen screen in Screen.AllScreens)
        {

            form_width += screen.Bounds.Width;
            form_height += screen.Bounds.Height;
            if (form_x > screen.Bounds.X)
            {
                minus_x = true;
                form_x = screen.Bounds.X;
            }
            if (form_y > screen.Bounds.Y)
            {
                minus_y = true;
                form_y = screen.Bounds.Y;
            }

            if (screen.Bounds.X < 0)
                sub_screen_width += screen.Bounds.Width;
            if (screen.Bounds.Y < 0)
                sub_screen_height += screen.Bounds.Height;
        }
        this.Width = form_width;
        this.Height = form_height;
        this.CenterToScreen();
        this.Location = new Point(form_x, form_y);

我应该为面板做什么?

标签: c#

解决方案


您可以使用 Screen.PrimaryScreen.WorkingArea。

panel1.Location = new Point(Screen.PrimaryScreen.WorkingArea.Left, Screen.PrimaryScreen.WorkingArea.Top);
panel1.Size = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);

顺便说一句,要跨多个屏幕显示表单,您不需要遍历所有屏幕,而是可以使用 VirtualScreen。

this.Size = new System.Drawing.Size(SystemInformation.VirtualScreen.Width, 
                                        SystemInformation.VirtualScreen.Height);
this.Location = new Point(SystemInformation.VirtualScreen.Left,
                              SystemInformation.VirtualScreen.Top);

您可以在此处阅读有关 VirtualScreen的更多信息


推荐阅读