1. Import the System. Runtime. InteropServices namespace.
2. The ShowWindow () API function can control the real state of a person and a form. Its declaration format is as follows:
Copy codeThe Code is as follows: [DllImport ("user32.dll")]
Public static extern int ShowWindow (int hwnd, int nCmdShow );
Hwnd indicates the handle of the form, and nCmdShow indicates the actual state of the form.
3. the API function FindWindow () can be used to return the "Shell_TrayWnd" handle of the Form class in the taskbar. The declaration format is as follows:
Copy codeThe Code is as follows: [DllImport ("user32.dll")]
Public static extern int FindWindow (string lpClassName, string lpWindowName );
The example is as follows. The main code is (two btn controls are used ):Copy codeThe Code is as follows: private const int SW_HIDE = 0; // hide the taskbar
Private const int SW_RESTORE = 9; // display the taskbar
[DllImport ("user32.dll")]
Public static extern int ShowWindow (int hwnd, int nCmdShow );
[DllImport ("user32.dll")]
Public static extern int FindWindow (string lpClassName, string lpWindowName );
Private void button#click (object sender, EventArgs e)
{
ShowWindow (FindWindow ("Shell_TrayWnd", null), SW_HIDE );
// YinYiNiao's Blog
}
Private void button2_Click (object sender, EventArgs e)
{
ShowWindow (FindWindow ("Shell_TrayWnd", null), SW_RESTORE );
}