需要写一个小系统,用托盘来显示是否有消息,就像QQ一样,有消息时托盘图标闪烁。
添加一个notifyicon控件
准备一张ico图片,设置一下相关属性
运行程序,就能在任务栏看到以下效果了。
下面来具体说一下它的一般用法
让它闪烁起来
找到两张交替的ico文件,添加成资源文件
加入一个timer,设置间隔,代码如下:
usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Management;usingSystem.Net.NetworkInformation;usingSystem.Security.Cryptography;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacetp{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privateIconnormal=Resource1.config;privateIconnormal1=Resource1.config1;privatebool_status=true;privatebool_isBlink=false;privatevoidtimer1_Tick(objectsender,EventArgse){if(_status)notifyIcon1.Icon=normal;elsenotifyIcon1.Icon=normal1;_status=!_status;}privatevoidbutton1_Click(objectsender,EventArgse){timer1.Enabled=true;timer1.Start();}privatevoidbutton3_Click(objectsender,EventArgse){timer1.Enabled=false;timer1.Stop();}}}
运行结果
弹出气球提示框及点击
privatevoidbutton4_Click(objectsender,EventArgse){//点击按钮弹出气球说明框notifyIcon1.ShowBalloonTip(,"你好","哈哈",ToolTipIcon.Info);}privatevoidnotifyIcon1_MouseUp(objectsender,MouseEventArgse){//点击托盘MessageBox.Show("你点击了我,还一笑而过.");}privatevoidnotifyIcon1_BalloonTipClicked(objectsender,EventArgse){//点击气球说明框MessageBox.Show("你伤害了我,还一笑而过.");}
当然也可以给托盘添加右键菜单,这个加一个
就可以了,如果有不会的可以