using System; using System.Drawing; using System.Windows.Forms; namespace ControlApp; public class MyCustomApplicationContext : ApplicationContext { private NotifyIcon trayIcon; public MyCustomApplicationContext() { trayIcon = new NotifyIcon(); trayIcon.Icon = new Icon("App.ico"); trayIcon.ContextMenuStrip = new ContextMenuStrip(); trayIcon.ContextMenuStrip.Items.Add("Exit", null, Exit); trayIcon.ContextMenuStrip.Items.Add("Open", null, Open); trayIcon.ContextMenuStrip.Items.Add("Panic", null, Panic); trayIcon.Visible = true; } private void Exit(object sender, EventArgs e) { trayIcon.Visible = false; Application.Exit(); } private void Open(object sender, EventArgs e) { using ControlApp myform = new ControlApp(); myform.ShowDialog(); } private void Panic(object sender, EventArgs e) { foreach (Form openForm in Application.OpenForms) { openForm.Close(); } } }