0

I have 3 monitors connection. I would like to cover up the entire 3 screens with the form and I would like to show the panel just in the center of the primary screen. How should I do this?

Right now I've covered up every screen with this code.

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

What should I do for the panel??

  • Are you using Winforms or WPF? With WPF you could simply define a grid with three columndefinitions. – colosso Jan 23 '19 at 07:30
  • Give it a look: [Using SetWindowPos with multiple monitors](https://stackoverflow.com/a/53026765/7444103) – Jimi Jan 23 '19 at 12:59

1 Answers1

0

You could make use of 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);

Btw, To show the form in across Multiple Screen, You dont need to loop through all screens, instead you could make use of VirtualScreen.

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

You could read more on VirtualScreen here

Anu Viswan
  • 17,797
  • 2
  • 22
  • 51