C # Minimize to pallet + double-click Pallet Recovery + Disable running multiple this program

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.