views:

5581

answers:

5

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.

A: 

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?

jdmichal
It's bad practice to change the user's chosen settings based on YOUR preferences. It's better to find out how to use the APIs to get the behavior you desire in the right way.
Wedge
That setting only applies to windowed apps, not full screen apps. Because when I play games or put my web browser to full screen it'll cover up the task bar.
Joel
Full screen apps like games are switching the display mode to DirectX or OpenGL or something else completely outside the windowing system, that gives the program raw video buffer access. This is from within the windowing system, so the setting I mentioned applies.
jdmichal
A: 

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();
paulbeesley
+8  A: 

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.

Kyralessa
I think that helps, but it still doesn't always get it... :/
Joel
For this to work, you want to make sure the form is *not* maximized.
Kyralessa
Oh, the only problem is I can't have it be TopMost, because I have other windows that are over it that are TopMost, and so if I click on 'this' then all the other windows will go behind it.
Joel
Heh. Minor detail there. I have my doubts about whether what you want can be done *without* TopMost if the user has "Keep the taskbar on top of other windows" checked. But you can also have multiple TopMost windows, and the active one will be the, uh, TopMostest.
Kyralessa
A: 

Here's a tricky one.

My main form can run either in windowed mode, or you can put the app into a fullscreen mode, in which TopMost is set to true, and the form size is set to the full screen size in an identical way to that mentioned above.

However, I'm now running into a problem. I want to have tool windows in the app, which will clearly also need to be set to TopMost. The problem is that when one of the controls on the parent form is clicked, it is brought to the front and hides all the other tool windows.

What I'm looking for I guess is some way to specify a rigid, invariable Z-order for all of my TopMost forms ... and I have no idea how to do this! Does anyone have any ideas?

Curtis
A: 

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(); } }

Ronen