WPF 系统托盘 图标闪烁

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();
             }

你可能感兴趣的:(WPF,wpf,c#,开发语言)