views:

1418

answers:

4

I have a Winforms app that I am trying to make full screen (somewhat like what VS does in full screen mode).

Currently I am setting FormBorderStyle to None and WindowState to maximized which gives me a little more space, but it doesn't cover over the taskbar if it is visible.

What do I need to do to use that space as well?

For bonus points, is there something I can do to make my MenuStrip autohide to give up that space as well?

+1  A: 

You need to set your window to be topmost.

No dice. Even if I set the window to be topmost it doesn't cover up the taskbar.
Try:Bounds = Screen.PrimaryScreen.Bounds;http://www.codeproject.com/KB/cs/scrframework.aspx has more details, like for multimon
A: 

I recently made an Mediaplayer application and I used API-calls to make sure the taskbar was hidden when the program was running fullscreen and then restored the taskbar when the program was not in fullscreen or not had focus or was exited.

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer

Sub HideTrayBar()
 Try


  Dim tWnd As Integer = 0
  Dim bWnd As Integer = 0
  tWnd = FindWindow("Shell_TrayWnd", vbNullString)
  bWnd = FindWindowEx(tWnd, bWnd, "BUTTON", vbNullString)
  ShowWindow(tWnd, 0)
  ShowWindow(bWnd, 0)
 Catch ex As Exception
  'Error hiding the taskbar, do what you want here..
 End Try
End Sub
Sub ShowTraybar()
 Try
  Dim tWnd As Integer = 0
  Dim bWnd As Integer = 0
  tWnd = FindWindow("Shell_TrayWnd", vbNullString)
  bWnd = FindWindowEx(tWnd, bWnd, "BUTTON", vbNullString)
  ShowWindow(bWnd, 1)
  ShowWindow(tWnd, 1)
 Catch ex As Exception
 'Error showing the taskbar, do what you want here..  
               End Try


End Sub
Stefan
What if two programs did this?What if your program crashes before it gets a chance to unhide the taskbar?
Tmdean
@Tmdean: In my case it was not an problem, this program was running on mashines that was dedicated to run only my program on screens in waitingrooms.
Stefan
@Tmdean: The point about if two programs did this is valid, it could mess things up if not handled correct.
Stefan
+2  A: 

And for the menustrip-question, try set MenuStrip1.Parent = Nothing when in fullscreen mode, it should then disapear.

And when exiting fullscreenmode, reset the menustrip1.parent to the form again and the menustrip will be normal again.

Stefan
+7  A: 

To the base question, the following will do the trick (hiding the taskbar)

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

But, interestingly, if you swap those two lines the Taskbar remains visible. I think the sequence of these actions will be hard to control with the properties window.

Henk Holterman
The ordering issue is why it wasn't working for me before. I was actually setting the properties in that order, but when the form is already maximized setting the border to none doesn't expand to cover the taskbar. I worked around by "restoring" the form changing the border and then maximizing.