Requirements:
1 when the program starts, no system tray
2 when the program is minimized, the tray is displayed and the program is hidden
3 double-click System Tray, show main interface, tray hide
4 system Tray Right click on the Show and Exit button, main program display and exit
Code
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;namespace systemicon{public partial class Form1:form {public Form1 () {InitializeComponent (); } private void Form1_Load (object sender, EventArgs e) {} private void Form1_Resize (object sen Der, EventArgs e) {if (this. WindowState = = formwindowstate.minimized) {//Minimize display of system tray, main interface hidden notifyicon1.visible = true; This. Visible = false; } else {//hide system tray Notifyicon1.visible = false; }} private void Notifyicon1_doubleclick (object sender, EventArgs e) {this. Visible = true; Displays the main window this. WindowState = Formwindowstate.normal; This. Activate ();//Get Focus NOTIFYICON1.Visible = false;//Hidden tray} private void display Toolstripmenuitem_click (object sender, EventArgs e) { Show main program Notifyicon1_doubleclick (sender, E); private void Exits Toolstripmenuitem_click (object sender, EventArgs e) {//exits this. Close (); Application.exit (); } }}
Description
1 adding NotifyIcon and ContextMenuStrip
2 Using the NotifyIcon ContextMenuStrip Property Association ContextMenuStrip
C # NotifyIcon Add system Tray