public static void AttachToSystemTray() { var ctx = new ContextMenu(); var menuExit = new MenuItem { Text = TextResource.GetText("MENU_EXIT") }; menuExit.Click += (_, _) => Environment.Exit(0); var menuRestore = new MenuItem { Text = TextResource.GetText("MSG_RESTORE") }; menuRestore.Click += (sender, e) => TrayClick?.Invoke(sender, e); ctx.MenuItems.Add(menuRestore); ctx.MenuItems.Add(menuExit); notifyIcon = new NotifyIcon { Text = "XDM", Visible = true, Icon = new Icon(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "xdm-logo.ico")), ContextMenu = ctx }; notifyIcon.MouseClick += NotifyIcon_MouseClick; }
private static void NotifyIcon_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { TrayClick?.Invoke(sender, e); } }
void NotifyIcon1_MouseClick(object sender, MouseEventArgs e) { TrayClick?.Invoke(this, e); }
void NotifyIcon1_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) { TrayClick?.Invoke(this, e); }