Question

I'm using Windows Vista and C#.net 3.5, but I had my friend run the program on XP and has the same problem.

So I have a C# program that I have running in the background with an icon in the SystemTray. I have a low level keyboard hook so when I press two keys (Ctr+windows in this case) it'll pull of the application's main form. The form is set to be full screen in the combo key press even handler:

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

So it basically works. When I hit CTR+Windows it brings up the form, no matter what program I have given focus to. But sometimes, the taskbar will still show up over the form, which I don't want. I want it to always be full screen when I hit that key combo.

I figure it has something to do with what application has focus originally. But even when I click on my main form, the taskbar sometimes stays there. So I wonder if focus really is the problem. It just seems like sometimes the taskbar is being stubborn and doesn't want to sit behind my program.

Anyone have any ideas how I can fix this?

EDIT: More details- I'm trying to achieve the same effect that a web browser has when you put it into fullscreen mode, or when you put powerpoint into presentation mode.

In a windows form you do that by putting the border style to none and maximizing the window. But sometimes the window won't cover the taskbar for some reason. Half the time it will.

If I have the main window topmost, the others will fall behind it when I click on it, which I don't want if the taskbar is hidden.

Was it helpful?

Solution

Try this (where this is your form):

this.Bounds = Screen.PrimaryScreen.Bounds;
this.TopMost = true;

That'll set the form to fullscreen, and it'll cover the taskbar.

OTHER TIPS

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.

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.F11)
        if (FormBorderStyle == FormBorderStyle.None)
        {
            FormBorderStyle = FormBorderStyle.Sizable;
            WindowState = FormWindowState.Normal;
        }
        else
        {
            SuspendLayout();
            FormBorderStyle = FormBorderStyle.None;
            WindowState = FormWindowState.Maximized;
            ResumeLayout();
        }
}

As far as I know, the taskbar is either above or below windows based on the "Keep the taskbar on top of other windows" setting. (At least, that's the wording in XP.) I suppose you could try to see if you can detect this setting and toggle it if needed?

Try resizing the form and bringing it to the front of the z-order like so:

        Rectangle screenRect = Screen.GetBounds(this);
        this.Location = screenRect.Location;
        this.Size = screenRect.Size;
        this.BringToFront();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top