Overview
The function of adding the tray icon is to add the menu function, which can be managed by the tray icon, and the tray menu includes "Open save directory, record Flash animation, record GIF animation, delay 5 seconds, set, exit" and other functions.
System Tray
The system tray is a special area, usually at the bottom of the desktop, where users can access the programs that are running at any time. In Microsoft Windows, the system tray usually refers to the status area of the taskbar, which is often referred to as the bulletin board area on GNOME's desktop, and the system tray on the KDE desktop. In each system, the pallet is a shared area of all applications that are running in the desktop environment.
Add tray icon
In Form1 form design mode, move the mouse to the left toolbox, pop up the Toolbox main panel, find NotifyIcon in common controls, and double-click it
Double-click to find a "notifyIcon1" below the form
With "NotifyIcon1" selected, set the Text property in the Properties window on the right: Screen tool
Add icon Resource
Select Menu: Project properties and select resource to switch to Icon view
Click the Add Resource drop-down button to add an existing file
Select a pre-prepared icon file to determine
Add the following code in the "Form1_Load" event:
This.notifyIcon1.Icon = Properties.resources.cutimage;this.notifyicon1.visible = true;
Compile, run, and you can see on the taskbar that the mouse moves to the tray icon and displays the property information just set on the "screen tool".
Add Tray Menu
Open Toolbox menu and Toolbars double-click "ContextMenuStrip" to add the right-click menu
Add a menu item, that line (delimiter) just enter a minus sign to do it.
The menu text is in Chinese, so the menu name will also have Chinese, I do not want the code variable name in Chinese, so the name of the exit to "Tsmi_exit"
Double-click on the Exit menu item to add code
private void Tsmi_exit_click (object sender, EventArgs e) { application.exit (); }
Adding code in the "Form1_Load" event handling
This.notifyIcon1.ContextMenuStrip = THIS.CONTEXTMENUSTRIP1;
Compile, run, click the right mouse button on the tray icon, you can see the following menu, choose to quit, you can exit the program.
The function of the tray icon and menu is complete.