有一個控件你找找看,哪一個我也記不清了!

解决方案 »

  1.   

    System.Windows.Fomrs.NotifyIcon类  
        System.Windows.Forms.ContextMenu类  
        System.Windows.Forms.MenuItem类  
        System.Windows.Forms.Label类  
        System.Windows.Forms.Timer类  
           
          
        在Visual  Studio下新建一个C#的工程,不妨命名为AnimateSystemTray。图示如下:  
          设计程序的主界面:  
          
        先将窗体的Text属性设置为"动画系统图标示例",MaximiseBox、MinimiseBox、ShowInTaskbar属性均设置为False。  
          
        再往窗体上添加Label控件、NotifyIcon控件、ContextMenu控件、Timer控件各一个。  
          
        将Label控件的Text属性设置为"请右击系统托盘图标";将NotifyIcon控件的Icon属性设置为一个图标文件:  ,Text属性设置为"这是个示例程序!",ContextMenu属性设置为"contextMenu1";接下来开始编辑ContextMenu控件,图示如下:  
          
        最后还要在导入两个图标  (Icon1.ico),  (Icon2.ico)文件到该项目。  
       现在我们开始编写代码部分:  
          
        首先在我们的类中添加以下数据成员:  
          
        private  Icon  m_Icon1;  
        private  Icon  m_Icon2;  
        private  bool  m_bFlag;  
        private  bool  m_bShowWnd;  
          
        修改Form1()函数为:  
          
        public  Form1()  
        {  
        //  
        //  Required  for  Windows  Form  Designer  support  
        //  
        InitializeComponent();  
        //  
        //  TODO:  Add  any  constructor  code  after  InitializeComponent  call  
        //  
        m_bFlag=true;  
        m_bShowWnd=true;  
          
        try  
        {  
        m_Icon1  =  new  Icon("Icon1.ico");//导入图标文件  
        m_Icon2  =  new  Icon("Icon2.ico");  
        }  
        catch  (  Exception  e  )  
        {  
        MessageBox.Show("Error  "  +  e.Message,"Animate  Tray  -  Error");  
        menuItem2.Enabled  =  false;  
        menuItem3.Enabled  =  false;  
        }  
        }  
          
        添加menuItem1、menuItem2、menuItem3、m_trayIcon的Click事件,消息处理函数如下:  
        private  void  menuItem1_Click(object  sender,  System.EventArgs  e)  
        {  
        timer1.Start();//打开计时器  
        }  
          
        private  void  menuItem2_Click(object  sender,  System.EventArgs  e)  
        {  
        timer1.Stop();//停止计时器  
        }  
          
        private  void  menuItem3_Click(object  sender,  System.EventArgs  e)  
        {  
        Application.Exit();//退出应用程序  
        }  
          
        private  void  m_trayIcon_Click(object  sender,  System.EventArgs  e)  
        {  
        if(m_bShowWnd  ==  true)//隐藏主界面  
        {  
        this.Visible  =  false;  
        m_bShowWnd  =  false;  
        }  
        else//显示主界面  
        {  
        this.Visible  =  true;  
        m_bShowWnd  =  true;  
        }  
        }  
          
          
          
        最后还要添加timer1的Tick()函数:  
          
        private  void  timer1_Tick(object  sender,  System.EventArgs  e)  
        {  
        if  (  m_Icon1  !=  null  &&  m_Icon2  !=  null  )  //如果两个图标文件都被正确载入  
        {  
        //只要timer1被启动,则在两个图标之间不断进行选择变换,实现动画效果  
        if  (  m_bFlag  ==  true  )  
        {  
        m_trayIcon.Icon  =  m_Icon2;  
        m_bFlag  =  false;  
        }  
        else  
        {  
        m_trayIcon.Icon  =  m_Icon1;  
        m_bFlag  =  true;  
        }  
        }  
        }
      

  2.   

    对,就是那控件,呵。原来还可以这么简单的