C#隐藏与显示系统任务栏和开始菜单栏按钮

时间:2023-12-29 10:49:20

隐藏与显示系统任务栏和开始菜单栏按钮:
直接上代码:
       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);