Windows的任务栏实际上是一个没有标题的窗体,所以只要找到这个窗体,就能隐藏和显示了 [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)] static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)] static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow); private void button1_Click(object sender, EventArgs e) { IntPtr trayHwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);//在窗口列表中寻找与指定条件相符的第一个子窗口,如果未找到返回0 //IntPtr trayHwnd = FindWindow("Shell_TrayWnd", null);//寻找窗口列表中第一个符合指定条件的顶级窗口,可用api函数GetWindowText取得这个窗口的名称 /*hwnd The handle of the window to change the show status of. nCmdShow Exactly one of the following flags specifying how to show the window: SW_HIDE = 0 Hide the window. SW_MAXIMIZE = 3 Maximize the window. SW_MINIMIZE = 6 Minimize the window. SW_RESTORE = 9 Restore the window (not maximized nor minimized). SW_SHOW = 5 Show the window. SW_SHOWMAXIMIZED = 3 Show the window maximized. SW_SHOWMINIMIZED = 2 Show the window minimized. SW_SHOWMINNOACTIVE = 7 Show the window minimized but do not activate it. SW_SHOWNA = 8 Show the window in its current state but do not activate it. SW_SHOWNOACTIVATE = 4 Show the window in its most recent size and position but do not activate it. SW_SHOWNORMAL = 1 Show the window and activate it (as usual).*/ if (button1.Text == "隐藏") { if (trayHwnd != IntPtr.Zero) { ShowWindow(trayHwnd, 0); button1.Text = "显示"; } } else { ShowWindow(trayHwnd,1); button1.Text = "隐藏"; } }