Advertisement
Guest User

devloop

a guest
Feb 14th, 2010
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.73 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Drawing;
  4. using System.Threading;
  5. using System.Windows.Forms;
  6.  
  7. namespace ClipTray
  8. {
  9.     public sealed class NotificationIcon
  10.     {
  11.         private NotifyIcon notifyIcon;
  12.         private ContextMenu notificationMenu;
  13.         private string[,] liste = new String[,] {
  14.             {"TOTO", "toto"},
  15.             {"BIDULE", "machin"}};
  16.        
  17.         #region Initialize icon and menu
  18.         public NotificationIcon()
  19.         {
  20.             notifyIcon = new NotifyIcon();
  21.             notificationMenu = new ContextMenu(InitializeMenu());
  22.            
  23.             notifyIcon.DoubleClick += IconDoubleClick;
  24.             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NotificationIcon));
  25.             notifyIcon.Icon = (Icon)resources.GetObject("$this.Icon");
  26.             notifyIcon.ContextMenu = notificationMenu;
  27.         }
  28.        
  29.         private MenuItem[] InitializeMenu()
  30.         {
  31.             MenuItem[] menu = new MenuItem[liste.GetLength(0) + 2];
  32.             int x = 0;
  33.             for (x = 0; x < liste.GetLength(0); x++)
  34.             {
  35.                 menu[x] = new MenuItem(liste[x, 0], miseEnTampon);
  36.             }
  37.             menu[x++] = new MenuItem("About", menuAboutClick);
  38.             menu[x++] = new MenuItem("Exit", menuExitClick);
  39.             return menu;
  40.         }
  41.         #endregion
  42.        
  43.         #region Main - Program entry point
  44.         /// <summary>Program entry point.</summary>
  45.         /// <param name="args">Command Line Arguments</param>
  46.         [STAThread]
  47.         public static void Main(string[] args)
  48.         {
  49.             Application.EnableVisualStyles();
  50.             Application.SetCompatibleTextRenderingDefault(false);
  51.            
  52.             bool isFirstInstance;
  53.             // Please use a unique name for the mutex to prevent conflicts with other programs
  54.             using (Mutex mtx = new Mutex(true, "ClipTray", out isFirstInstance)) {
  55.                 if (isFirstInstance) {
  56.                     NotificationIcon notificationIcon = new NotificationIcon();
  57.                     notificationIcon.notifyIcon.Visible = true;
  58.                     Application.Run();
  59.                     notificationIcon.notifyIcon.Dispose();
  60.                 } else {
  61.                     // The application is already running
  62.                     // TODO: Display message box or change focus to existing application instance
  63.                 }
  64.             } // releases the Mutex
  65.         }
  66.         #endregion
  67.        
  68.         #region Event Handlers
  69.         private void menuAboutClick(object sender, EventArgs e)
  70.         {
  71.             MessageBox.Show("ClipTray - devloop");
  72.         }
  73.        
  74.         private void menuExitClick(object sender, EventArgs e)
  75.         {
  76.             Application.Exit();
  77.         }
  78.        
  79.         private void IconDoubleClick(object sender, EventArgs e)
  80.         {
  81.             MessageBox.Show("Passer par le click droit pour le menu.");
  82.         }
  83.        
  84.         private void miseEnTampon(object sender, EventArgs e)
  85.         {
  86.             MenuItem mi = sender as MenuItem;
  87.             int x = 0;
  88.             for (x = 0; x < liste.GetLength(0); x++)
  89.             {
  90.                 if (mi.Text == liste[x, 0])
  91.                 {
  92.                     Clipboard.SetText(liste[x, 1]);
  93.                     break;
  94.                 }
  95.             }
  96.         }
  97.         #endregion
  98.     }
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement