徐州 網(wǎng)站建設(shè)百度一下 你就知道官網(wǎng)
實現(xiàn)步驟
-
為了能夠控制Windows任務(wù)欄,我們需要利用Windows API提供的功能。具體來說,我們會使用到
user32.dll
中的兩個函數(shù):FindWindow
和ShowWindow
。這兩個函數(shù)可以幫助我們找到任務(wù)欄窗口,并對其執(zhí)行顯示或隱藏的操作 -
引入命名空間:首先,我們在項目中引入
System.Runtime.InteropServices
命名空間,以便能夠調(diào)用非托管代碼(即Windows API)。 -
聲明API函數(shù):接著,我們需要聲明將要使用的API函數(shù)。
模塊代碼:
using System.Runtime.InteropServices;[DllImport("user32.dll")]private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);[DllImport("user32.dll")]private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);// 定義常量private const int SW_HIDE = 0;private const int SW_SHOW = 5;/// <summary>/// 隱藏任務(wù)欄/// </summary>public void HideTaskbar(){var handle = FindWindow("Shell_TrayWnd", null);if (handle != IntPtr.Zero){ShowWindow(handle, SW_HIDE); // 隱藏任務(wù)欄}}/// <summary>/// 顯示任務(wù)欄/// </summary>public void ShowTaskbar(){var handle = FindWindow("Shell_TrayWnd", null);if (handle != IntPtr.Zero){ShowWindow(handle, SW_SHOW); // 顯示任務(wù)欄}}
調(diào)用方法
private void button1_Click(object sender, EventArgs e){HideTaskbar();}private void button2_Click(object sender, EventArgs e){ShowTaskbar();}
參考連接
C#實現(xiàn)隱藏和顯示任務(wù)欄 (qq.com)https://mp.weixin.qq.com/s?__biz=MzA5MjczOTQ5Mw==&mid=2458677568&idx=1&sn=39bdfb8c49a29f71e6bedf0e0ac2caab&chksm=862ea8bdda23a3d60621324bc02d38ee76bc4d08e58d179f1d86f7157dfce6fc7771b93960ea&mpshare=1&scene=1&srcid=1029yNjQpwRtYpGNGwMdIhrp&sharer_shareinfo=0b1ac58bebcdbd40c4f3399599cf9e06&sharer_shareinfo_first=0b1ac58bebcdbd40c4f3399599cf9e06#rd
特此記錄
anlog
2024年10月29日