Maximize form on both screens (dual screen monitor)

不羁岁月 提交于 2019-12-21 05:52:11

问题


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 set by .NET Framework to reflect the Primary screen. I want to MAXIMIZE Form to BOTH screens but after clicking the "maximize button", dialog is maximized only to "active" screen (active I mean screen on which dialog is currently placed).

Iam not interested in bounds solution, this works, but when clicked Maximize button it forces the dialog back to one of 2 screens.

I would be gratefull for any help or hints.


回答1:


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)




回答2:


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



回答3:


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;



回答4:


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




回答5:


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.




回答6:


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!



来源:https://stackoverflow.com/questions/3361211/maximize-form-on-both-screens-dual-screen-monitor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!