当前位置:网站首页>WPF 系统托盘 图标闪烁
WPF 系统托盘 图标闪烁
2022-08-09 12:59:00 【执着的涛】
using System.Windows.Forms;
using System.Windows.Threading;
public partial class Window : Window
{
private NotifyIcon notifyIcon;
DispatcherTimer icoTimer = new DispatcherTimer();
string icoUrl = @"../../Red.ico";
string icoUrl2 = @"../../Red2.ico";
public long i = ;
public Window()
{
InitializeComponent();
//不在任务栏显示
this.ShowInTaskbar = false;
this.notifyIcon = new NotifyIcon();
this.notifyIcon.BalloonTipText = "系统监控中... ...";
this.notifyIcon.ShowBalloonTip();
this.notifyIcon.Text = "系统监控中... ...";
//this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath);
this.notifyIcon.Icon = new System.Drawing.Icon(@"../../Red.ico");
this.notifyIcon.Visible = true;
//打开菜单项
System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open");
open.Click += new EventHandler(Show);
//退出菜单项
System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit");
exit.Click += new EventHandler(Close);
//关联托盘控件
System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] { open, exit };
notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);
this.notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler((o, e) =>
{
if (e.Button == MouseButtons.Left) this.Show(o, e);
//this.Visibility = System.Windows.Visibility.Visible;
//this.ShowInTaskbar = true;
//this.Activate();
NavigationWindow win = new MainWindow();
this.notifyIcon.Visible = false;
win.ShowDialog();
});
//闪烁图标
icoTimer.Interval = TimeSpan.FromSeconds(0.3);
icoTimer.Tick += new EventHandler(IcoTimer_Tick);
icoTimer.Start();
}
public void IcoTimer_Tick(object sender, EventArgs e)
{
i=i+;
if (i % != )
{
this.notifyIcon.Icon = new System.Drawing.Icon(icoUrl);
}
else
{
this.notifyIcon.Icon = new System.Drawing.Icon(icoUrl2);
}
}
private void Show(object sender, EventArgs e)
{
this.Visibility = System.Windows.Visibility.Visible;
this.ShowInTaskbar = true;
this.Activate();
}
private void Hide(object sender, EventArgs e)
{
this.ShowInTaskbar = false;
this.Visibility = System.Windows.Visibility.Hidden;
}
private void Close(object sender, EventArgs e)
{
System.Windows.Application.Current.Shutdown();
}
边栏推荐
猜你喜欢
阿里大淘系模型治理阶段性分享
GIN Bind mode to get parameters and form validation
5G China unicom repeater network management protocol real-time requirements
Flutter introduction advanced trip (5) Image Widget
30行代码实现蚂蚁森林自动偷能量
安踏携手华为运动健康共同验证冠军跑鞋 创新引领中国体育
快来扔鸡蛋。
19、学习MySQL 索引
电脑重装系统还原0x80070005错误如何解决
gin's middleware and routing grouping
随机推荐
glibc memory management model freeing C library memory cache
乐东消防救援大队应邀为干部开展消防安全培训
[极客大挑战 2019]Upload
阿里大淘系模型治理阶段性分享
GIN a preliminary study, the environment is installed
ftplib+ tqdm upload and download progress bar
十进制数字→十六进制字符
Flutter entry and advanced tour (6) Layout Widget
Dry+Bean+Dataset R语言数据分析,报告英文
透明tune proxy
问题系列-如何修改或更新localhost里的值
搭建大型分布式服务(四)Docker搭建开发环境安装Mysql
为什么文字不贴合边
Redis源码剖析之robj(redisObject)
时间序列分析课程实验报告
Deep Learning Based on R Language - Simple Regression Case
Professor Chen Qiang the machine learning and R application course chapter 18 assignments
七夕力扣刷不停,343. 整数拆分(剑指 Offer 14- I. 剪绳子、剑指 Offer 14- II. 剪绳子 II)
面试攻略系列(三)-- 高级开发工程师面试问些啥?
Flutter introduction advanced trip (5) Image Widget