具有表单和面板的MultiMonitor

时间:2019-01-23 07:27:29

标签: c#

我有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);

我应该为面板做什么?

1 个答案:

答案 0 :(得分:0)

您可以使用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 here

上阅读更多内容