Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Drawing;
- using System.Threading;
- using System.Windows.Forms;
- namespace ClipTray
- {
- public sealed class NotificationIcon
- {
- private NotifyIcon notifyIcon;
- private ContextMenu notificationMenu;
- private string[,] liste = new String[,] {
- {"TOTO", "toto"},
- {"BIDULE", "machin"}};
- #region Initialize icon and menu
- public NotificationIcon()
- {
- notifyIcon = new NotifyIcon();
- notificationMenu = new ContextMenu(InitializeMenu());
- notifyIcon.DoubleClick += IconDoubleClick;
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NotificationIcon));
- notifyIcon.Icon = (Icon)resources.GetObject("$this.Icon");
- notifyIcon.ContextMenu = notificationMenu;
- }
- private MenuItem[] InitializeMenu()
- {
- MenuItem[] menu = new MenuItem[liste.GetLength(0) + 2];
- int x = 0;
- for (x = 0; x < liste.GetLength(0); x++)
- {
- menu[x] = new MenuItem(liste[x, 0], miseEnTampon);
- }
- menu[x++] = new MenuItem("About", menuAboutClick);
- menu[x++] = new MenuItem("Exit", menuExitClick);
- return menu;
- }
- #endregion
- #region Main - Program entry point
- /// <summary>Program entry point.</summary>
- /// <param name="args">Command Line Arguments</param>
- [STAThread]
- public static void Main(string[] args)
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- bool isFirstInstance;
- // Please use a unique name for the mutex to prevent conflicts with other programs
- using (Mutex mtx = new Mutex(true, "ClipTray", out isFirstInstance)) {
- if (isFirstInstance) {
- NotificationIcon notificationIcon = new NotificationIcon();
- notificationIcon.notifyIcon.Visible = true;
- Application.Run();
- notificationIcon.notifyIcon.Dispose();
- } else {
- // The application is already running
- // TODO: Display message box or change focus to existing application instance
- }
- } // releases the Mutex
- }
- #endregion
- #region Event Handlers
- private void menuAboutClick(object sender, EventArgs e)
- {
- MessageBox.Show("ClipTray - devloop");
- }
- private void menuExitClick(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void IconDoubleClick(object sender, EventArgs e)
- {
- MessageBox.Show("Passer par le click droit pour le menu.");
- }
- private void miseEnTampon(object sender, EventArgs e)
- {
- MenuItem mi = sender as MenuItem;
- int x = 0;
- for (x = 0; x < liste.GetLength(0); x++)
- {
- if (mi.Text == liste[x, 0])
- {
- Clipboard.SetText(liste[x, 1]);
- break;
- }
- }
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement