C#托盘程序示例- 知行合一- 博客园
代码
        public MainForm()
        {
            InitializeComponent();
            InitNotifyIcon();            
        }

        
private void InitNotifyIcon()
        {
            MenuItem[] mi
=new MenuItem[3];
            mi[
0]=new MenuItem();
            mi[
0].Text="显示";
            mi[
0].Click+= new EventHandler(this.FormShow);        
            mi[
1]=new MenuItem();
            mi[
1].Text="-";    
            mi[
2]=new MenuItem();
            mi[
2].Text="退出";
            mi[
2].Click+=new EventHandler(this.FormClose);    
            ContextMenu cm
=new ContextMenu(mi);

            notifyIcon1.MouseDoubleClick
+=new MouseEventHandler(notifyIcon1_MouseDoubleClick);
            notifyIcon1.Icon
=new Icon("Zipped 4.ico");
            notifyIcon1.Text
="已运行 - \\\\数据上报程序";
            notifyIcon1.Visible
=true;
            notifyIcon1.ContextMenu
=cm;
        }
        
private void FormShow(object sender, EventArgs e)
        {
            
this.Visible=true;
        }
        
private void FormClose(object sender, EventArgs e)
        {
            
this.Close();
        }
        
        
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            
this.Visible=true;
        }
        
        
const int WM_SYSCOMMAND = 0x112;
        
const int SC_CLOSE = 0xF060;
        
const int SC_MINIMIZE = 0xF020;
        
const int SC_MAXIMIZE = 0xF030;
        
protected override void WndProc(ref Message m)
        {
            
if(m.Msg==WM_SYSCOMMAND)
            {
                
if(m.WParam.ToInt32()==SC_CLOSE)
                {
                    
this.Visible=false;
                    
return;
                }
                
if(m.WParam.ToInt32()==SC_MINIMIZE)
                {
                    
this.Visible=false;
                    
return;
                }
            }
            
base.WndProc(ref m);
        }

 

posted on 2010-05-12 23:16 阅读(6)   所属分类:

郑重声明:资讯 【C#托盘程序示例- 知行合一- 博客园】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——