Advertisement
Kantheshamurthy

NotifyIcon - App

Jul 5th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. namespace NotifyIconKanthesh
  2. {
  3.     /// <summary>
  4.     /// Interaction logic for App.xaml
  5.     /// </summary>
  6.     public partial class App : Application
  7.     {
  8.  
  9.           /// <summary>
  10.         /// Represents the notify icon for the applicaion.
  11.         /// </summary>
  12.         private System.Windows.Forms.NotifyIcon notify;
  13.  
  14.         public App()
  15.         {
  16.  
  17.         }
  18.  
  19.         /// <summary>
  20.         /// Raises the <see cref="E:System.Windows.Application.Exit"/> event.
  21.         /// </summary>
  22.         /// <param name="e">An <see cref="T:System.Windows.ExitEventArgs"/> that contains the event data.</param>
  23.         protected override void OnExit(ExitEventArgs e)
  24.         {
  25.             if (this.notify != null)
  26.             {
  27.                 this.notify.Dispose();
  28.             }
  29.             base.OnExit(e);
  30.         }
  31.  
  32.         /// <summary>
  33.         /// Raises the <see cref="E:System.Windows.Application.Startup"/> event.
  34.         /// </summary>
  35.         /// <param name="e">A <see cref="T:System.Windows.StartupEventArgs"/> that contains the event data.</param>
  36.         protected override void OnStartup(StartupEventArgs e)
  37.         {
  38.             base.OnStartup(e);
  39.             InitializeNotifyIcon();
  40.         }
  41.  
  42.  
  43.         private void InitializeNotifyIcon()
  44.         {
  45.             notify = new System.Windows.Forms.NotifyIcon();
  46.             notify.Text = "Kanthesha Murthy";
  47.             notify.Icon = NotifyIconKanthesh.Properties.Resources.Error;
  48.             notify.Visible = true;
  49.             notify.ContextMenu = new System.Windows.Forms.ContextMenu(new System.Windows.Forms.MenuItem[]
  50.             {
  51.                 new System.Windows.Forms.MenuItem("Show compass", (s, e) => this.MainWindow.Show()),
  52.                 new System.Windows.Forms.MenuItem("Hide compass", (s, e) => this.MainWindow.Hide()),
  53.                 new System.Windows.Forms.MenuItem("-"),
  54.                 new System.Windows.Forms.MenuItem("Close", (s, e) => this.Shutdown())
  55.             });
  56.         }
  57.  
  58.     }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement