74

I have a .net windows application that needs to run in full screen. When the application starts however the taskbar is shown on top of the main form and it only disappears when activating the form by clicking on it or using ALT-TAB. The form's current properties are as follow:

  • WindowState=FormWindowState.Normal
  • TopMost=Normal
  • Size=1024,768 (this is the screen resolution of the machines it's going to be running on)
  • FormBorderStyle = None

I've tried adding the followings on form load but none worked for me:

  • this.Focus(); (after giving the focus this.Focus property is always false)
  • this.BringToFront();
  • this.TopMost = true; (this however would not be ideal in my scenario)
  • this.Bounds = Screen.PrimaryScreen.Bounds;
  • this.Bounds = Screen.PrimaryScreen.Bounds;

Is there a way to do it within .NET or would I have to invoke native windows methods and if so a code snippet would very much be appreciated.

many thanks

T30
  • 11,422
  • 7
  • 53
  • 57
myquestionoftheday
  • 911
  • 1
  • 7
  • 9

9 Answers9

128

Use:

FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;

And then your form is placed over the taskbar.

driconmax
  • 956
  • 1
  • 18
  • 32
TcKs
  • 25,849
  • 11
  • 66
  • 104
  • 1
    I was a day late and a dollar short I guess. – Christopher B. Adkins Feb 16 '10 at 10:16
  • Send printscreen, how it looks. This is standard way, which I successfuly use for this task. I think there will be some other problem. – TcKs Feb 16 '10 at 10:31
  • sorry but I can't send screen grabs for customer reasons. It basically is a form with no borders that takes the whole screen size but when it first starts is shown behind the taskbar, until you then click on the form which activates it and brings it on top of the taskbar. thanks – myquestionoftheday Feb 16 '10 at 10:41
  • 2
    The start bar is still visible when this technique is used. – Dan Gifford Jan 19 '15 at 15:50
  • 4
    it does not work for me, it still doesnt cover the taskbar – r.hamd Aug 29 '15 at 11:10
69

I've tried so many solutions, some of them works on Windows XP and all of them did NOT work on Windows 7. After all I write a simple method to do so.

private void GoFullscreen(bool fullscreen)
    {
        if (fullscreen)
        {
            this.WindowState = FormWindowState.Normal;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Bounds = Screen.PrimaryScreen.Bounds;
        }
        else
        {
            this.WindowState = FormWindowState.Maximized;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
        }
    }

the order of code is important and will not work if you change the place of WindwosState and FormBorderStyle.

One of the advantages of this method is leaving the TOPMOST on false that allow other forms to come over the main form.

It absolutely solved my problem.

mammadalius
  • 3,263
  • 6
  • 39
  • 47
16

This is how I make forms full screen.

private void button1_Click(object sender, EventArgs e)
{
    int minx, miny, maxx, maxy;
    inx = miny = int.MaxValue;
    maxx = maxy = int.MinValue;

    foreach (Screen screen in Screen.AllScreens)
    {
        var bounds = screen.Bounds;
        minx = Math.Min(minx, bounds.X);
        miny = Math.Min(miny, bounds.Y);
        maxx = Math.Max(maxx, bounds.Right);
        maxy = Math.Max(maxy, bounds.Bottom);
    }

    Form3 fs = new Form3();
    fs.Activate();
    Rectangle tempRect = new Rectangle(1, 0, maxx, maxy);
    this.DesktopBounds = tempRect;
}
Afzaal Ahmad Zeeshan
  • 15,669
  • 12
  • 55
  • 103
15

My simple fix it turned out to be calling the form's Activate() method, so there's no need to use TopMost (which is what I was aiming at).

Smi
  • 13,850
  • 9
  • 56
  • 64
myquestionoftheday
  • 911
  • 1
  • 7
  • 9
7

A tested and simple solution

I've been looking for an answer for this question in SO and some other sites, but one gave an answer was very complex to me and some others answers simply doesn't work correctly, so after a lot code testing I solved this puzzle.

Note: I'm using Windows 8 and my taskbar isn't on auto-hide mode.

I discovered that setting the WindowState to Normal before performing any modifications will stop the error with the not covered taskbar.

The code

I created this class that have two methods, the first enters in the "full screen mode" and the second leaves the "full screen mode". So you just need to create an object of this class and pass the Form you want to set full screen as an argument to the EnterFullScreenMode method or to the LeaveFullScreenMode method:

class FullScreen
{
    public void EnterFullScreenMode(Form targetForm)
    {
        targetForm.WindowState = FormWindowState.Normal;
        targetForm.FormBorderStyle = FormBorderStyle.None;
        targetForm.WindowState = FormWindowState.Maximized;
    }

    public void LeaveFullScreenMode(Form targetForm)
    {
        targetForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
        targetForm.WindowState = FormWindowState.Normal;
    }
}

Usage example

    private void fullScreenToolStripMenuItem_Click(object sender, EventArgs e)
    {
        FullScreen fullScreen = new FullScreen();

        if (fullScreenMode == FullScreenMode.No)  // FullScreenMode is an enum
        {
            fullScreen.EnterFullScreenMode(this);
            fullScreenMode = FullScreenMode.Yes;
        }
        else
        {
            fullScreen.LeaveFullScreenMode(this);
            fullScreenMode = FullScreenMode.No;
        }
    }

I have placed this same answer on another question that I'm not sure if is a duplicate or not of this one. (Link to the other question: How do I make a WinForms app go Full Screen)

Community
  • 1
  • 1
Zignd
  • 6,896
  • 12
  • 40
  • 62
  • 1
    This has lots of problems in Win7: the taskbar still shows over the window for about a second when entering fullscreen, other fullscreen windows render instead of the taskbar when exiting fullscreen, and it doesn't save WindowState, so if you go fullscreen while maximized you come back with a window that isn't maximized. (Why is it still hard to fullscreen windows?) – Glenn Maynard May 03 '14 at 21:03
  • @GlennMaynard For the "...it doesn't save WindowState..." issue I ended up adding a bool on my Form that indicates whether the form was previously maximized before going full screen; unfortunately I wasn't able to reliably reproduce the other problems you're having on Windows 7 x64 in either Aero or Windows Classic. – jrh Mar 08 '17 at 19:50
  • 3
    Still works on Windows 10 and handles multiple monitors correctly (only solution here that seems to do that) – Garr Godfrey Mar 20 '18 at 09:27
6
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
falsetru
  • 357,413
  • 63
  • 732
  • 636
Enes Okullu
  • 303
  • 3
  • 6
3

I believe that it can be done by simply setting your FormBorderStyle Property to None and the WindowState to Maximized. If you are using Visual Studio both of those can be found in the IDE so there is no need to do so programmatically. Make sure to include some way of closing/exiting the program before doing this cause this will remove that oh so helpful X in the upper right corner.

EDIT:

Try this instead. It is a snippet that I have kept for a long time. I can't even remember who to credit for it, but it works.

/*
 * A function to put a System.Windows.Forms.Form in fullscreen mode
 * Author: Danny Battison
 * Contact: gabehabe@googlemail.com
 */

        // a struct containing important information about the state to restore to
        struct clientRect
        {
            public Point location;
            public int width;
            public int height;
        };
        // this should be in the scope your class
        clientRect restore;
                bool fullscreen = false;

        /// <summary>
        /// Makes the form either fullscreen, or restores it to it's original size/location
        /// </summary>
        void Fullscreen()
        {
            if (fullscreen == false)
            {
                this.restore.location = this.Location;
                this.restore.width = this.Width;
                this.restore.height = this.Height;
                this.TopMost = true;
                this.Location = new Point(0,0);
                this.FormBorderStyle = FormBorderStyle.None;
                this.Width = Screen.PrimaryScreen.Bounds.Width;
                this.Height = Screen.PrimaryScreen.Bounds.Height;
            }
            else
            {
                this.TopMost = false;
                this.Location = this.restore.location;
                this.Width = this.restore.width;
                this.Height = this.restore.height;
                                // these are the two variables you may wish to change, depending
                                // on the design of your form (WindowState and FormBorderStyle)
                this.WindowState = FormWindowState.Normal;
                this.FormBorderStyle = FormBorderStyle.Sizable;
            }
        }
Christopher B. Adkins
  • 3,499
  • 2
  • 26
  • 29
  • sorry, I should have said it before, FormBorderStyle is already set to None but setting the WindowState to Maximized did not solve the problem. Thanks for your answer anyway – myquestionoftheday Feb 16 '10 at 10:29
  • "this.TopMost" puts your frame on top (duh) but that includes on top of the taskbar and everything. – Christopher B. Adkins Feb 16 '10 at 10:40
  • yes, by using your snippet the screen is finally on top of the taskbar however, as I mention in my original question, using setting TopMost to true is not desirable in my app and without it the snippet does not work any longer. – myquestionoftheday Feb 16 '10 at 10:58
  • 3
    This will work only on primary screen. If you have 2 screen desktop it will not work! You must find which screen the form is originally on, and then use that Screen object to stretch the form: `Screen myScreen = Screen.FromHandle(this.Handle);` now myScreen is any screen the form is on, and not always PrimaryScreen as you put in your code. :) :P – Cipi Jul 29 '11 at 12:59
  • to add to Cipi's comment i think Screen.GetBounds(panel1); works too. – colin lamarre Apr 04 '19 at 00:08
2

I'm not have an explain on how it works, but works, and being cowboy coder is that all I need.

        System.Drawing.Rectangle rect = Screen.GetWorkingArea(this);
        this.MaximizedBounds = Screen.GetWorkingArea(this);
        this.WindowState = FormWindowState.Maximized;
-5
FormBorderStyle = FormBorderStyle.Sizable;
TopMost = false;
WindowState = FormWindowState.Normal;

THIS CODE MAKE YOUR WINDOWS FULL SCREEN THIS WILL ALSO COVER WHOLE SCREEN