Windows Form Full Screen Goes Beyond Screens

I have a WinForms application (.NET 4) that should display either fullscreen or maximized without borders.

Using the following code in the event Form_Shown:

#if (DEBUG)
    var debug = true;
#else
    var debug = false;
#endif

this.Text = "";
this.ControlBox = false;
this.ShowInTaskbar = true;
//this.TopMost = debug;
this.TopLevel = true;
this.FormBorderStyle = FormBorderStyle.None;

if (debug) { this.Bounds = Screen.FromControl(this).WorkingArea; }
else { this.WindowState = FormWindowState.Maximized; }

If you look closely at the screenshot below, the upper and lower areas are cropped a few pixels. In addition, if it is maximized, the window still does not cover the taskbar.

Please note that I only have one monitor. No additional displays.

Any suggestions on how to solve the two above issues will be appreciated.

Application maximized screenshot

UPDATE: The above code works fine with forms without MenuStripor StatusStrip.

+4
1

, . FullScreen , , 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;
        }
    }
}
+4

Source: https://habr.com/ru/post/1609280/


All Articles