我最近开发了一个 MediapPlayer 应用程序,我使用 API 调用来确保在程序运行全屏时隐藏任务栏,然后在程序没有全屏、没有焦点或退出时恢复任务栏。
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
private void Form1_Load(object sender, EventArgs e)
{
// hide max,min and close button at top right of Window
this.FormBorderStyle = FormBorderStyle.None;
// fill the screen
this.Bounds = Screen.PrimaryScreen.Bounds;
}
无须使用:
this.TopMost = true;
That line interferes with alt+tab to switch to other application. ("TopMost" means the window stays on top of other windows, unless they are also marked "TopMost".)
I've been looking for an answer for this question in SO and some other sites, but one gave an answer was very complex to me and some others answers simply doesn't work correctly, so after a lot code testing I solved this puzzle.
注意: 我正在使用 Windows 8,我的任务栏没有处于自动隐藏模式。
我发现,在执行任何修改之前将 WindowState 设置为 Normal 将停止未覆盖任务栏的错误。
密码
我创建了这个类,它有两个方法,第一个进入“全屏模式”,第二个离开“全屏模式”。所以你只需要创建这个类的一个对象,然后把你想设置全屏的 Form 作为参数传递给 EnterFullScreenMode 方法或者 LeaveFullScreenMode 方法: