2

I have WinForm application and i want to enter fullscreen mode and remove all bars and the task bar. i done it with this:

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

The top bar is really hidden but the Windows TaskBar is still visible. Any idea what can be the trouble?

YosiFZ
  • 7,792
  • 21
  • 114
  • 221

3 Answers3

6

Run with full screen you can use this method..

private void Form1_Load(object sender, EventArgs e)
{
    this.TopMost = true;
    this.FormBorderStyle = FormBorderStyle.None;
    this.WindowState = FormWindowState.Maximized;
}

To Hide TaskBar Just add this class into your project .it works as you expected.

using System;
using System.Runtime.InteropServices;

public class Taskbar
{
    [DllImport("user32.dll")]
    private static extern int FindWindow(string className, string windowText);

    [DllImport("user32.dll")]
    private static extern int ShowWindow(int hwnd, int command);

    [DllImport("user32.dll")]
    public static extern int FindWindowEx(int parentHandle, int childAfter, string className, int windowTitle);

    [DllImport("user32.dll")]
    private static extern int GetDesktopWindow();

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

    protected static int Handle
    {
        get
        {
            return FindWindow("Shell_TrayWnd", "");
        }
    }

    protected static int HandleOfStartButton
    {
        get
        {
            int handleOfDesktop = GetDesktopWindow();
            int handleOfStartButton = FindWindowEx(handleOfDesktop, 0, "button", 0);
            return handleOfStartButton;
        }
    }

    private Taskbar()
    {
        // hide ctor
    }

    public static void Show()
    {
        ShowWindow(Handle, SW_SHOW);
        ShowWindow(HandleOfStartButton, SW_SHOW);
    }

    public static void Hide()
    {
        ShowWindow(Handle, SW_HIDE);
        ShowWindow(HandleOfStartButton, SW_HIDE);
    }
}

USAGE:

Taskbar.Hide();
Thilina H
  • 5,754
  • 6
  • 26
  • 56
2

Reorder lines to maximize the form after will will be marked with FormBorderStyle.None and TopMost

this.FormBorderStyle = FormBorderStyle.None;
this.TopMost = true;
this.WindowState = FormWindowState.Maximized;
PashaPash
  • 1,972
  • 15
  • 38
0

You need to reorder your statements, try:

    this.TopMost = true;
    this.FormBorderStyle = FormBorderStyle.None;
    this.WindowState = FormWindowState.Maximized;
tomsullivan1989
  • 2,760
  • 14
  • 21