Hide the taskbar and start button in C#

The example Make a form cover the taskbar and start button in C# explains how you can make a form cover the entire desktop, but the taskbar and start button are still there. If you really want to hide the taskbar and start button you can do so but it’s a lot more work.

This program uses a bunch of API functions. Download the example to see how they are declared.

When the example program starts, it uses the following code to hide the taskbar and start button.

// The taskbar's window handle.
private IntPtr TaskbarHWnd, StartButtonHWnd;

// Hide the taskbar and start button.
private void Form1_Load(object sender, EventArgs e)
{
    // Get the taskbar's and start button's window handles.
    TaskbarHWnd = FindWindow("Shell_traywnd", "");
    StartButtonHWnd = FindWindowEx(IntPtr.Zero,
        IntPtr.Zero, (IntPtr)0xC017, null);

    // Hide the taskbar and start button.
    SetWindowPos(TaskbarHWnd, IntPtr.Zero, 0, 0, 0, 0,
        SetWindowPosFlags.SWP_HIDEWINDOW);
    SetWindowPos(StartButtonHWnd, IntPtr.Zero, 0, 0, 0, 0,
        SetWindowPosFlags.SWP_HIDEWINDOW);

    // Maximize.
    this.Bounds = Screen.PrimaryScreen.Bounds;
}

The form’s Load event handler uses the FindWindow API function to find the window named Shell_traywnd, the taskbar’s window. It then uses the FindWindowEx API function to find window 0xC017, the start button. It saves the window handles for these windows in class-level variables.

Next the code uses the SetWindowPos API funtion to hide both of those windows. This makes the taskbar and start button disappear.

If you now maximize the form, it will not cover the area where the taskbar would be if it were present. The form’s Load event handler finishes by setting the form’s bounds to match those of the primary screen, which will include the area where the taskbar should be.

If you hide the taskbar and start button, be sure to restore them when you’re done so the user can use them. This example does this in the following FormClosing event handler.

// Restore the taskbar and start button.
private void Form1_FormClosing(object sender,
    FormClosingEventArgs e)
{
    SetWindowPos(TaskbarHWnd, IntPtr.Zero, 0, 0, 0, 0,
        SetWindowPosFlags.SWP_SHOWWINDOW);
    SetWindowPos(StartButtonHWnd, IntPtr.Zero, 0, 0, 0, 0,
        SetWindowPosFlags.SWP_HIDEWINDOW);
}

This code uses the SetWindowPos API function to show the taskbar and start button.

You can use SetWindowPos to do other things, too, such as setting position, minimizing, or maximizing a window that’s not in your program.

Download the example to see other details such as the definitions of the API functions and the flags they use.


Download Example   Follow me on Twitter   RSS feed   Donate








This entry was posted in forms, system and tagged , , , , , , , , , , . Bookmark the permalink.

One Response to Hide the taskbar and start button in C#

  1. Ganesh says:

    Worked on XP for me.

Leave a Reply

Your email address will not be published. Required fields are marked *