百度空间 | 百度首页 
 
查看文章
 
C# 实现窗体最小化到托盘
2007年03月16日 星期五 09:39

上网搜了搜 自己改写了下

首先把form的 showtaskBar 设为 false;

再添加notifyIcon控件 notifyIcon1 ,icon属性里改为你要用的图标,visible设为false 因为初始不显示托盘图标,当然你也可以开始就显示

代码里输入

private bool show ;//一个flag

private void Form1_SizeChanged(object sender, EventArgs e)
     {
            
             if (this.WindowState == FormWindowState.Minimized) {//判断是否最小化
                 this.Visible = false;//隐藏
                 this.notifyIcon1.Visible = true;
                 show = false;

             }
    }

private void notifyIcon1_DoubleClick(object sender, System.EventArgs e) {
     if (!show)
             {
                 this.Visible = true;
                 this.WindowState = FormWindowState.Normal;
                 show = true;
             }
             else if (show) {
                 this.Visible = false;
                 this.WindowState = FormWindowState.Minimized;
                 show = false;
             }
}

基本就是这样.


类别:默认分类 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu