隱藏與顯示系統任務欄和開始菜單欄按鈕:
直接上代碼:
private const int SW_HIDE = 0; //隱藏
private const int SW_RESTORE= 5; //顯示
[DllImportAttribute("user32.dll")]
private static extern int FindWindow(string ClassName,string WindowName);
[DllImport("user32.dll")]
private static extern int ShowWindow(int handle,int cmdShow);
//隱藏
private void button3_Click(object sender, EventArgs e)
{
ShowWindow(FindWindow("Shell_TrayWnd", null), SW_HIDE);//隱藏系統任務欄
ShowWindow(FindWindow("Button", null), SW_HIDE);//隱藏系統開始菜單欄按鈕
}
//顯示
private void button2_Click(object sender, EventArgs e)
{
ShowWindow(FindWindow("Shell_TrayWnd", null), SW_RESTORE);//顯示系統任務欄
ShowWindow(FindWindow("Button", null), SW_RESTORE);//顯示系統開始菜單欄按鈕
}
說明:
(1)引用了系統API函數,需要引用命名空間
using System.Runtime.InteropServices;
(2)ShowWindow()參數類型是一些int類型,可以查看MDNS
也可以寫成
ShowWindow(FindWindow("Shell_TrayWnd", null), 0);