日期:2011-06-04 浏览次数:20417 次
System.Windows.Fomrs.NotifyIcon类 System.Windows.Forms.ContextMenu类 System.Windows.Forms.MenuItem类 System.Windows.Forms.Label类 System.Windows.Forms.Timer类 |
private Icon m_Icon1; private Icon m_Icon2; private bool m_bFlag; private bool m_bShowWnd; |
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; } } |
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; } } } |