Click here to Skip to main content
12,620,909 members (35,225 online)
Click here to Skip to main content
Add your own
alternative version


92 bookmarked

How To Make a Windows Form App Truly Full Screen (and Hide Taskbar) in C#

, 3 Dec 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
One of the sounds-like-simple questions is “how to make your application truly Full Screen” i.e. not showing Taskbar or anything like that on the screen estate
Sample Image - MaxWinForm.png


One of the sounds-like-simple questions is “how to make your application truly Full Screen”, i.e. not showing Taskbar or anything like that.

The initial approach is obvious...

targetForm.WindowState = FormWindowState.Maximized;
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.TopMost = true;

... assuming that the target form is referenced with targetForm.

Does it work? Well, sort of. If your Taskbar has default setting unchecked for “Keep the taskbar on top of other Windows”, this will present your application in all its glory all over the screen estate.

However, if the Taskbar is set to appear on top of all others, this won't help - your application won't cover it.

Update For This Approach

In the discussion of the article (below) Azlan David (thanks David!) suggested to try this approach:

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

(Just changed the order of property assignments.) It does the work on all Win XP SP2 computers where I had the opportunity to test it; however, on one Win 2003 SP1 computer, this did not help; I'm still investigating why.

Let’s go further - the next step is to use P/Invoke and to engage the Win32 API services. There is an easy way to hide a particular window. So, find the Taskbar and hide it:

private const int SW_HIDE = 0;
private const int SW_SHOW = 1;

private static extern int FindWindow(string className, string windowText);
private static extern int ShowWindow(int hwnd, int command);

int hWnd = FindWindow("Shell_TrayWnd", "");
ShowWindow(hWnd, SW_HIDE);

targetForm.WindowState = FormWindowState.Maximized;
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.TopMost = true;

(You need to add using System.Runtime.InteropServices;)

Is this better? In theory, yes - the Taskbar is hidden, but your application still does not occupy the whole screen - the place where the Taskbar was is not used.

The real and proven solution is to make a request to WinAPI that your form take the whole screen estate - Taskbar will hide itself in that case. Full information about that can be found in the KB article Q179363: How To Cover the Task Bar with a Window.

The steps are as follows:

  • Find out the dimension of the screen estate by calling GetSystemMetrics
  • Set the dimensions of your form to full screen

Here is the actual code:

/// <span class="code-SummaryComment"><summary></span>
/// Selected Win API Function Calls
/// <span class="code-SummaryComment"></summary></span>

public class WinApi
    [DllImport(”user32.dll”, EntryPoint = “GetSystemMetrics”)]
    public static extern int GetSystemMetrics(int which);

    public static extern void
        SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
                     int X, int Y, int width, int height, uint flags);        

    private const int SM_CXSCREEN = 0;
    private const int SM_CYSCREEN = 1;
    private static IntPtr HWND_TOP = IntPtr.Zero;
    private const int SWP_SHOWWINDOW = 64; // 0×0040

    public static int ScreenX
        get { return GetSystemMetrics(SM_CXSCREEN);}

    public static int ScreenY
        get { return GetSystemMetrics(SM_CYSCREEN);}

    public static void SetWinFullScreen(IntPtr hwnd)
        SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);

/// <span class="code-SummaryComment"><summary></span>
/// Class used to preserve / restore / maximize state of the form
/// <span class="code-SummaryComment"></summary></span>
public class FormState
    private FormWindowState winState;
    private FormBorderStyle brdStyle;
    private bool topMost;
    private Rectangle bounds;

    private bool IsMaximized = false;

    public void Maximize(Form targetForm)
        if (!IsMaximized)
            IsMaximized = true;
            targetForm.WindowState = FormWindowState.Maximized;
            targetForm.FormBorderStyle = FormBorderStyle.None;
            targetForm.TopMost = true;

    public void Save(Form targetForm)
        winState = targetForm.WindowState;
        brdStyle = targetForm.FormBorderStyle;
        topMost = targetForm.TopMost;
        bounds = targetForm.Bounds;

    public void Restore(Form targetForm)
        targetForm.WindowState = winState;
        targetForm.FormBorderStyle = brdStyle;
        targetForm.TopMost = topMost;
        targetForm.Bounds = bounds;
        IsMaximized = false;

Now you can use the above class in your WinForms application like this:

public partial class MaxForm : Form
    FormState formState = new FormState();

    public MaxForm()

    private void button1_Click(object sender, EventArgs e)

    private void button2_Click(object sender, EventArgs e)

The full code and example application can be downloaded from the link at the top of this article.


  • 3rd December, 2006: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Serbia Serbia
Highly skilled, very efficient, organized and focused senior programmer and project manager.

Specialist for the E-commerce solutions based on Microsoft Web technologies on top of MS SQL or Oracle database servers.

13 years of experience. Strong in .Net (C# / ASP.NET), XML, JavaScript, DHTML, Database design, PL/SQL, T-SQL, ADO / ADO.NET, scripting and shell languages (Awk, CMD, 4Dos / 4NT).

You may also be interested in...


Comments and Discussions

QuestionThis is simple and it works Pin
trantrum28-Dec-15 9:36
professionaltrantrum28-Dec-15 9:36 
QuestionDoesn't work on Windows 8. Pin
Xiaoming Tu19-Sep-14 3:22
memberXiaoming Tu19-Sep-14 3:22 
AnswerRe: Doesn't work on Windows 8. Pin
serge074-Dec-14 6:28
memberserge074-Dec-14 6:28 
AnswerConfirmation Pin
Cengiz Araz17-Jul-14 23:55
memberCengiz Araz17-Jul-14 23:55 
GeneralMy vote of 5 Pin
manoj kumar choubey23-Feb-12 22:40
membermanoj kumar choubey23-Feb-12 22:40 
GeneralEasier Still Pin
gutharius12-Jan-11 7:05
membergutharius12-Jan-11 7:05 
GeneralRe: Easier Still Pin
johannesnestler23-Feb-12 23:32
memberjohannesnestler23-Feb-12 23:32 
Generalhiding the mouse cursor on fullscreen.. Pin
asgz26-Jul-10 0:28
memberasgz26-Jul-10 0:28 
QuestionDoes this work on Multi-Monitor systems? Pin
quintic20-May-10 13:04
memberquintic20-May-10 13:04 
QuestionHow to make a windows application in .net such that it goes full screen and disable the keyboard at the same time Pin
keeks12311-Feb-09 22:20
memberkeeks12311-Feb-09 22:20 
AnswerRe: How to make a windows application in .net such that it goes full screen and disable the keyboard at the same time Pin
Dejan.Vesic11-Feb-09 22:31
memberDejan.Vesic11-Feb-09 22:31 
QuestionHi, Does anyone know how to do this in C++/CLI ? Pin
shadowfaxe2-Sep-08 4:39
membershadowfaxe2-Sep-08 4:39 
GeneralSimpler way to get screen bounds PinPopular
maciej_jl19-Dec-07 8:16
membermaciej_jl19-Dec-07 8:16 
GeneralTaskbar not hiding Pin
CodeHook25-Sep-07 1:36
memberCodeHook25-Sep-07 1:36 
GeneralControlbox Pin
jamesrgoodwin21-Aug-07 7:26
memberjamesrgoodwin21-Aug-07 7:26 
GeneralThank you Pin
vaximillian26-Mar-07 6:56
membervaximillian26-Mar-07 6:56 
Generalconvert to, please HELP Pin
tlin504317-Dec-06 23:13
membertlin504317-Dec-06 23:13 
GeneralRe: convert to, please HELP Pin
Dejan.Vesic17-Dec-06 23:19
memberDejan.Vesic17-Dec-06 23:19 
GeneralRe: convert to, please HELP Pin
ixup26-Aug-08 4:47
memberixup26-Aug-08 4:47 
QuestionHow to use on Pocket PC? Pin
Kitro15-Dec-06 6:57
memberKitro15-Dec-06 6:57 
AnswerRe: How to use on Pocket PC? Pin
Dejan.Vesic15-Dec-06 11:37
memberDejan.Vesic15-Dec-06 11:37 
AnswerRe: How to use on Pocket PC? Pin
Ashvin Gunga20-Feb-07 19:56
memberAshvin Gunga20-Feb-07 19:56 
GeneralAdditional details.. Pin
Skylan Hill7-Dec-06 19:24
memberSkylan Hill7-Dec-06 19:24 
GeneralSimpler Way Pin
Azlan David5-Dec-06 7:15
memberAzlan David5-Dec-06 7:15 
GeneralRe: Simpler Way Pin
Dejan.Vesic5-Dec-06 7:36
memberDejan.Vesic5-Dec-06 7:36 
GeneralRe: Simpler Way Pin
Azlan David5-Dec-06 21:49
memberAzlan David5-Dec-06 21:49 
GeneralRe: Simpler Way Pin
Dejan.Vesic5-Dec-06 23:19
memberDejan.Vesic5-Dec-06 23:19 
GeneralRe: Simpler Way Pin
Azlan David6-Dec-06 0:36
memberAzlan David6-Dec-06 0:36 
GeneralRe: Simpler Way Pin
Dejan.Vesic6-Dec-06 0:55
memberDejan.Vesic6-Dec-06 0:55 
QuestionVery nice, but can you... Pin
KGilbert4-Dec-06 8:41
memberKGilbert4-Dec-06 8:41 
AnswerRe: Very nice, but can you... Pin
Dejan.Vesic4-Dec-06 9:03
memberDejan.Vesic4-Dec-06 9:03 
AnswerRe: Very nice, but can you... Pin
Azlan David5-Dec-06 22:22
memberAzlan David5-Dec-06 22:22 
GeneralWell Done Pin
aprenot4-Dec-06 7:29
memberaprenot4-Dec-06 7:29 
GeneralRe: Well Done Pin
Dejan.Vesic4-Dec-06 8:23
memberDejan.Vesic4-Dec-06 8:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161128.1 | Last Updated 3 Dec 2006
Article Copyright 2006 by Dejan.Vesic
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid