WPF System Tray Icon flashing, wpf Tray

Source: Internet
Author: User

WPF System Tray Icon flashing, wpf Tray

WPF Message notification

System Tray, icon flashing

1 using System. windows. forms; 2 3 using System. windows. threading; 4 5 public partial class Window: Window 6 {7 private policyicon; 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 is not displayed on the taskbar. showInTaskbar = false; 17 this. policyicon = n Ew policyicon (); 18 this. policyicon. balloonTipText = "in system monitoring ...... "; 19 this. policyicon. showBalloonTip (2000); 20 this. policyicon. text = "in system monitoring ...... "; 21 // this. policyicon. icon = System. drawing. icon. extractAssociatedIcon (System. windows. forms. application. executablePath); 22 this. policyicon. icon = new System. drawing. icon (@".. /.. /Red. ico "); 23 this. policyicon. visible = true; 24 // Open menu item 25 System. windows. for Ms. menuItem open = new System. windows. forms. menuItem ("Open"); 26 open. click + = new EventHandler (Show); 27 // exit menu item 28 System. windows. forms. menuItem exit = new System. windows. forms. menuItem ("Exit"); 29 exit. click + = new EventHandler (Close); 30 // associate the tray Control 31 System. windows. forms. menuItem [] childen = new System. windows. forms. menuItem [] {open, exit}; 32 policyicon. contextMenu = new System. windows. forms. contex TMenu (childen); 33 34 this. policyicon. 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. policyicon. visible = false; 42 win. showDialog (); 43}); 44 45 46 // flashing icon 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. policyicon. icon = new System. drawing. icon (icoUrl); 57} 58 else59 {60 this. policyicon. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.