using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AnimateSystemTray
{
public partial class Form1 : Form
{
private Icon icon1;
private Icon icon2;//声明
string a = "1";//判断托盘图标是icon1还是icon2
public Form1()
{
InitializeComponent();
try
{
icon1 = new Icon("clover.ico");
icon2 = new Icon("cloverbunch.ico");//引入图标文件,文件需放在debug目录下
}
catch(Exception err)//捕捉错误信息
{
MessageBox.Show("出错" + err.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
notifyIcon1.Text = "动态系统托盘图标示例" + "\n" + "designed by yoyo";
timer1.Start();//time1启动
notifyIcon1.Icon = icon1;
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
if (icon1 != null && icon2 != null) //如果两个图标文件都被正确载入
{
if (a=="1")//如果托盘图标为icon1,则更改为icon2
{
notifyIcon1.Icon = icon2;
a ="2";
}
else//否则则将图标设置为icon1
{
notifyIcon1.Icon = icon1;
a = "1";
}
}
}
catch (Exception err)//捕捉错误信息
{
MessageBox.Show("错误信息:" + err.Message);
}
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ismart/archive/2009/11/12/4802881.aspx