0
votes

I am writing a Windows Forms application in C# which contains a window that is maximized without a title and it should be maximized and cover the taskbar (i.e. over the taskbar). This is very simple, I was able to achieve that by simply executing the following:

Text = "";
ControlBox = false;
FormBorderStyle = FormBorderStyle.None;

..before I open the form. The problem is, I also want to be able to toggle this behavior with a keystroke so I can show it normalized (with a title) and then be able to go back to maximized (without title). Problem is, when I go back to maximized, the taskbar is no longer covered by the window, it is visible, which it shouldn't be.

Does anybody know if this is possible to show, i.e. a maximized window without a title bar covering the taskbar or is that only possible the first time a window is opened? Also can it be toggled back and forth?

1
Taskbar visiblity is up to the user, not to you.TaW
Looking for FullScreen property?Reza Aghaei

1 Answers

0
votes

This should work:

bool IsFullScreen = false;      // Set this to true if you initially open 
                                // your form in full screen.
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.F)
    {
        if (!IsFullScreen)
        {
            // Changing the WindowState helps keeping the form over the taskbar.
            WindowState = FormWindowState.Normal;       
            FormBorderStyle = FormBorderStyle.None;
            WindowState = FormWindowState.Maximized;
            IsFullScreen = true;
        }
        else
        {
            FormBorderStyle = FormBorderStyle.Sizable;
            // WindowState = FormWindowState.Normal;   // uncomment this if you also don't 
                                                       // want the form to be maximized.
            IsFullScreen = false;
        }
    }
}

It will allow you to toggle the form between normal maximized (or restored) and full screen by pressing the F key. You might want to set the form's KeyPreview property to true if you'd like to catch the keystroke from any control on the form.

Hope that helps.