Maximize WPF Window on the current screen

后端 未结 10 682
谎友^
谎友^ 2021-01-31 07:35

I have a windowless wpf application, whenever I set the window state as maximized it maximizes it on the primary display.

What I would like to do is have it maximize on

10条回答
  •  清酒与你
    2021-01-31 08:31

    I had my application getting maximized in the secondary screen by doing this

    Add this at the top of the main window :

    using Screen = System.Windows.Forms.Screen;
    

    Add this in the maximize handler :

    private void AdjustWindowSize()
        {
            if (this.WindowState == WindowState.Maximized)
            {
                this.WindowState = WindowState.Normal;
            }
            else
            {
                System.Drawing.Rectangle r = Screen.GetWorkingArea(new System.Drawing.Point((int)this.Left, (int)this.Top));
                this.MaxWidth = r.Width;
                this.MaxHeight = r.Height;
                this.WindowState = WindowState.Maximized;
            }
        }
    

    Here we go !

提交回复
热议问题