WPF 系统托盘 图标闪烁_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > WPF 系统托盘 图标闪烁

WPF 系统托盘 图标闪烁

 2014/7/7 15:35:02  一剑天门开  程序员俱乐部  我要评论(0)
  • 摘要:WPF消息通知系统托盘,图标闪烁1usingSystem.Windows.Forms;23usingSystem.Windows.Threading;45publicpartialclassWindow:Window6{7privateNotifyIconnotifyIcon;8DispatcherTimericoTimer=newDispatcherTimer();9stringicoUrl=@"../../Red.ico";10stringicoUrl2=@"../../Red2.ico"
  • 标签:

WPF消息通知

系统托盘,图标闪烁

class="code_img_closed" src="/Upload/Images/2014070715/0015B68B3C38AA5B.gif" alt="" />logs_code_hide('11d4f7f4-8aa8-432f-bf37-ababe4cc5e12',event)" src="/Upload/Images/2014070715/2B1B950FA3DF188F.gif" alt="" />
 1     using System.Windows.Forms;
 2 
 3     using System.Windows.Threading;
 4 
 5     public partial class Window : Window
 6         {
 7             private NotifyIcon notifyIcon;
 8             DispatcherTimer icoTimer = new DispatcherTimer();
 9             string icoUrl = @"../../Red.ico";
10             string icoUrl2 = @"../../Red2.ico";
11             public long i = 0;
12             public Window()
13             {
14                 InitializeComponent();
15                 //不在任务栏显示
16                 this.ShowInTaskbar = false;
17                 this.notifyIcon = new NotifyIcon();
18                 this.notifyIcon.BalloonTipText = "系统监控中... ...";
19                 this.notifyIcon.ShowBalloonTip(2000);
20                 this.notifyIcon.Text = "系统监控中... ...";
21                 //this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath);
22                 this.notifyIcon.Icon = new System.Drawing.Icon(@"../../Red.ico");
23                 this.notifyIcon.Visible = true;
24                 //打开菜单项
25                 System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open");
26                 open.Click += new EventHandler(Show);
27                 //退出菜单项
28                 System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit");
29                 exit.Click += new EventHandler(Close);
30                 //关联托盘控件
31                 System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] { open, exit };
32                 notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);
33 
34                 this.notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler((o, e) =>
35                 {
36                     if (e.Button == MouseButtons.Left) this.Show(o, e);
37                     //this.Visibility = System.Windows.Visibility.Visible;
38                     //this.ShowInTaskbar = true;
39                     //this.Activate();
40                     NavigationWindow win = new MainWindow();
41                     this.notifyIcon.Visible = false;
42                     win.ShowDialog();
43                 });
44 
45 
46                 //闪烁图标
47                 icoTimer.Interval = TimeSpan.FromSeconds(0.3);
48                 icoTimer.Tick += new EventHandler(IcoTimer_Tick);
49                 icoTimer.Start();
50             }
51             public void IcoTimer_Tick(object sender, EventArgs e)
52             {
53                 i=i+1;
54                 if (i % 2 != 0)
55                 {
56                     this.notifyIcon.Icon = new System.Drawing.Icon(icoUrl);
57                 }
58                 else
59                 {
60                     this.notifyIcon.Icon = new System.Drawing.Icon(icoUrl2);
61                 }
62             }
63             private void Show(object sender, EventArgs e)
64             {
65                 this.Visibility = System.Windows.Visibility.Visible;
66                 this.ShowInTaskbar = true;
67                 this.Activate();
68             }
69 
70             private void Hide(object sender, EventArgs e)
71             {
72                 this.ShowInTaskbar = false;
73                 this.Visibility = System.Windows.Visibility.Hidden;
74             }
75 
76             private void Close(object sender, EventArgs e)
77             {
78                 System.Windows.Application.Current.Shutdown();
79             }
View Code

转自:http://www.cnblogs.com/ke10/archive/2012/11/16/NotifyIcon.html

 

记得对System.Windows.Forms添加引用。

 

  • 相关文章
发表评论
用户名: 匿名