Raheel Khan Raheel Khan - 1 year ago 91
C# Question

Full screen Windows Form goes beyond screen dimensions

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


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

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 top and bottom areas are cut off by a few pixels. Also, if maximized, the window still does not cover the task bar.

Please note that I have only one monitor attached. No secondary displays.

Any suggestions on how to address the two issues above would be appreciated.

Screenshot of app in maximized mode

UPDATE: The code above seems to work fine with forms without a

Answer Source

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;
public bool FullScreen
        return fullScreen;
        fullScreen = value;

        if (value)
            this.WindowState = FormWindowState.Normal;
            FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            WindowState = FormWindowState.Maximized;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;