Full screen Windows Form goes beyond screen dimensions

前端 未结 1 1723
迷失自我
迷失自我 2020-12-04 02:11

I have a WinForms app (.NET 4) that needs to be shown either full screen or maximized without borders.

Using the following code in the Form_Shown event:

相关标签:
1条回答
  • 2020-12-04 02:52

    Here is the code I use for fullscreen. I create a FullScreen property for my form and when I need, I set this.FullScreen = true;

    private bool fullScreen = false;
    [DefaultValue(false)]
    public bool FullScreen
    {
        get
        {
            return fullScreen;
        }
        set
        {
            fullScreen = value;
    
            if (value)
            {
                //this.SuspendLayout();
                this.WindowState = FormWindowState.Normal;
                FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                WindowState = FormWindowState.Maximized;
                //this.ResumeLayout(true);
            }
            else
            {
                this.Activate();
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题