Maximize form on both screens (dual screen monitor)

前端 未结 6 1162
春和景丽
春和景丽 2021-01-01 07:01

Iam looking for some hint or solution regarding following problem.

I have a .NET 2.0 WinForm dialog which operates in Dual Screen environment. The Working area is se

相关标签:
6条回答
  • 2021-01-01 07:18

    Only solution I know is using the bounds in combination with overriding the Resize event. In the handler you can check the WindowState property to see if the form is Maximized or Minimized. If maximized, resize the window again with all screen bounds together.

    I do see a problem with what you want.
    What if the second screen is smaller then the first (visa versa)...
    What if the second screen is located diagonal (e.g. top left) of the first screen (visa versa)...
    There will be parts that won't be visible!

    0 讨论(0)
  • 2021-01-01 07:20

    this may be late, but here is an easy way to do it. It sets the size of the form from getting the size of resolution. then it places the form so it can be visible.

            int screenLeft = SystemInformation.VirtualScreen.Left;
            int screenTop = SystemInformation.VirtualScreen.Top;
            int screenWidth = SystemInformation.VirtualScreen.Width;
            int screenHeight = SystemInformation.VirtualScreen.Height;            
    
            this.Size = new System.Drawing.Size(screenWidth, screenHeight);
            this.Location = new System.Drawing.Point(screenLeft, screenTop);
    
    0 讨论(0)
  • 2021-01-01 07:24

    Combine the 2 screen sizes and set your form to that resolution. Something like:

    int height = 0;
    int width = 0;
    foreach (screen in System.Windows.Forms.Screen.AllScreens)
    {
      //take smallest height
      height = (screen.Bounds.Height <= height) ? screen.Bounds.Height: height;
      width += screen.Bounds.Width;
    }
    
    Form1.Size = new System.Drawing.Size(width, height);
    

    To override the maximize button you can check via WndProc for the maximize event

    const int WM_SYSCOMMAND= 0x0112;
    const int SC_MAXIMIZE= 0xF030;
    protected override void WndProc(ref Message m)
    {
        if(m.Msg==WM_SYSCOMMAND)
        {
            if((int)m.WParam==SC_MAXIMIZE)
            {
                MessageBox.Show("Maximized!!");
                return;
            }
        }
        base.WndProc (ref m);
    }
    

    or register to the Resize event of the form (you should check if it's resize or an maximize) (MSDN)

    0 讨论(0)
  • 2021-01-01 07:29

    I know this thread is very old - but I found a very useful and working solution from here after trying and having problems with every solution listed here.

    What worked for me was

    Rectangle r = new Rectangle();
            foreach (Screen s in Screen.AllScreens)
            {
                if (s != Screen.FromControl(this)) // Blackout only the secondary screens
                    r = Rectangle.Union(r, s.Bounds);
            }
    
            this.Top = r.Top;
            this.Left = r.Left;
            this.Width = r.Width;
            this.Height = r.Height;
    
    0 讨论(0)
  • 2021-01-01 07:29

    Do not do it.

    Here we go: the behavior is as defined BY THE USER and the operating system. You should not override user wishes.

    Bonding of screens (to form one virtual screen) is possible with some hardware drivers (ATI comes to my mind for current cards, they call it EyeFinity).

    While I see the sense of it - in MOST cases it breaks user expectations of how the program would behave. And I say that as someone working with 3+ screens often ;) As in: using one program across all screens ;) I would NOT want that ;)

    0 讨论(0)
  • 2021-01-01 07:29

    Get the users to change their Windows display settings (or change it for them).

    For instance, on NVidia cards, the default Windows behaviour is called 'Dualview'. If you enable 'Horizontal span', then maximized windows will start behaving as you describe.

    0 讨论(0)
提交回复
热议问题