Maximize form on both screens (dual screen monitor)

前端 未结 6 1205
春和景丽
春和景丽 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: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)

提交回复
热议问题