Production of pallet programs:
1. Add the NotifyIcon control and add icon, otherwise the tray has no icon (the Tray Right-click menu can also be added directly in the attribute);
2. Resize or sizechanged messages in response to the form:
// Hide to System tray Private void Form1_Resize (object sender, EventArgs e) { if (this. WindowState = = formwindowstate.minimized ) {this. Hide (); This false ; This true ; } }
3. Double-click the tray icon to restore the DoubleClick message that responds to NotifyIcon:
// Show from system tray private void Notifyicon_doubleclick ( Object sender, EventArgs e) { if ( Span style= "color: #0000ff;" >this . WindowState == formwindowstate.minimized) { this . Show (); this . WindowState = Formwindowstate.normal; this . ShowInTaskbar = true = false ; } }
Prevent this program from running multiple edit Program.cs files at the same time (refer to 1:c# tips on how to prevent programs from running multiple times 2:[c# development tips] How to prevent programs from running multiple times)
usingSystem;usingSystem.Windows.Forms;usingSystem.Threading;namespacewhoonline{Static classProgram {/// <summary> ///The main entry point for the application. /// </summary>[STAThread]Static voidMain () { Mutex m = new Mutex (false, "Product_index_cntvs", out BOOL bcreatednew); if (bcreatednew) { application.enablevisualstyles (); Application.setcompatibletextrenderingdefault (false); Application.Run (NewForm1 ()); } Else {MessageBox.Show (" the application is already running ... " ); System.Threading.Thread.Sleep (+); // terminates this process and provides the specified exit code for the underlying operating system. System.Environment.Exit (1 ); } } }}
C # Minimize to pallet + double-click Pallet Recovery + Disable running multiple this program