推扬网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
推扬网 门户 经验分享 查看内容

c#实现隐藏与显示任务栏的方法详解

2020-4-11 13:52| 发布者: admin| 查看: 395| 评论: 0

本篇文章是对c#中任务栏隐藏与显示的实现方法进行了详细的分析介绍,需要的朋友参考下

1.导入System.Runtime.InteropServices命名空间。

2.API函数ShowWindow()能够控制人和窗体的现实状态,其声明格式如下:

[DllImport("user32.dll")]
public static extern int ShowWindow(int hwnd,int nCmdShow);
其中hwnd表示窗体的句柄,nCmdShow表示窗体的现实状态。

3.API函数FindWindow()可用于返回任务栏所在窗体类“Shell_TrayWnd”句柄,其声明格式如下:

[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName,string lpWindowName);
实例如下,主要代码为(使用了2个btn控件):

 private const int SW_HIDE = 0;  //隐藏任务栏
        private const int SW_RESTORE = 9;//显示任务栏

        [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 button1_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);
        }


鲜花

握手

雷人

路过

鸡蛋

最新评论

精选推荐

    广告服务|投稿要求|禁言标准|版权说明|免责声明|手机版|小黑屋|推扬网 ( 粤ICP备18134897号 )|网站地图 | 邮箱:vayae@hotmail.com

    GMT+8, 2025-6-14 16:03 , Processed in 0.097697 second(s), 28 queries .

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

    返回顶部