using System; using System.Windows.Forms; class Program { static void Main() { // Create the NotifyIcon instance and set its properties NotifyIcon icon = new NotifyIcon(); icon.Icon = new Icon("icon.ico"); icon.Text = "My Application"; // Add a click event handler to display a message box icon.Click += (sender, args) => { MessageBox.Show("Hello from My Application!"); }; // Add the icon to the system tray icon.Visible = true; // Wait for the user to close the application Application.Run(); } }
using System; using System.Windows.Forms; class Program { static void Main() { // Create the NotifyIcon instance and set its properties NotifyIcon icon = new NotifyIcon(); icon.Icon = new Icon("icon.ico"); icon.Text = "My Application"; // Create the context menu and add items ContextMenu menu = new ContextMenu(); menu.MenuItems.Add("Item 1", (sender, args) => { MessageBox.Show("You clicked Item 1!"); }); menu.MenuItems.Add("Item 2", (sender, args) => { MessageBox.Show("You clicked Item 2!"); }); // Set the context menu for the icon icon.ContextMenu = menu; // Add the icon to the system tray icon.Visible = true; // Wait for the user to close the application Application.Run(); } }This example creates a NotifyIcon instance with a context menu that displays two items when the icon is right-clicked. Each item has a click event handler that displays a different message box. The package library for the System.Windows.Forms NotifyIcon class is included in the .NET Framework, which is a software framework developed by Microsoft that runs on Microsoft Windows.