用户名称: 用户密码:
网站建设快速入口 | 宏蓝主页 | 加入收藏

广州网站建设|网站制作公司|网页设计论坛--广州宏蓝科技公司官方论坛 → 宏蓝吧 → 杂谈 → Winform将程序最小化到系统托盘
    
 
Winform将程序最小化到系统托盘
发起人:macroblue  回复数:0  浏览数:2691  最后更新:2011/1/8 13:57:18 by macroblue
分享到: 微信 更多

选择查看  帖子排序:
2011/1/8 13:57:18
macroblue





师长

角  色:版主
发 帖 数:8929
经 验 值:17688
注册时间:2009/7/23
联系 收藏 编辑 删除
Winform将程序最小化到系统托盘

C# winform程序怎样将程序最小化到系统托盘?

这样最简单!

1.在form中添加一个NotifyIcon控件     
 
2.把icon.ico这个图标放在\bin\Debug目录下  
 
using System;  
using System.Collections.Generic;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.Text;  
using System.Windows.Forms;  
 
namespace MinimizeForm  
{  
    public partial class Form1 : Form  
    {  
        public Form1()  
        {  
            InitializeComponent();  
        }  
 
        private void Form1_Load(object sender, EventArgs e)  
        {  
            this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);  
            notifyIcon1.Icon = new Icon(Application.StartupPath "\\icon.ico");//指定一个图标     

            notifyIcon1.Visible = false;  
            notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click);  
            this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);     
      
 
        }  
 
        private void Form1_SizeChanged(object sender, EventArgs e)  
        {  
            if (this.WindowState == FormWindowState.Minimized)//最小化     
            {  
                this.ShowInTaskbar = false;  
                this.notifyIcon1.Visible = true;  
            }     
 
        }  
 
              private void notifyIcon1_Click(object sender, EventArgs e)  
        {  
            if (this.WindowState == FormWindowState.Minimized)  
                this.WindowState = FormWindowState.Normal;  
            this.Activate();  
            this.notifyIcon1.Visible = false;  
            this.ShowInTaskbar = true;     
 
        }  
 
    }  
}

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/kevonz/archive/2010/01/06/5137475.aspx


客服热线:020-85562980 客服邮箱:service@macroblue.net
联系地址:广州中山大道89号国家软件产业基地天河软件园华景园区12-S05
版权所有 © 2003-2011    网站建设:宏蓝科技(Macroblue.NET)