Application applets that minimize pallets

Source: Internet
Author: User

Minimize applications to pallets: when the "close" button on the main form of a Single-Host application, the application is not closed, but minimized to the system tray (that is, the bottom right corner of the screen ), click the application on the system tray (or the "open" option in the menu), and the application subject is displayed again; when you click the "exit" option in the menu (the "close" button on the main form can also be used as the close button, the corresponding code will be given ), to exit the application and write a winforms application implementation process: 1. Open vs2008 to create a windows application; 2, drag a yyicon control and a ContextMenuStrip control in the default form form1 and set the image displayed by the NotifyIcon control. (select notifyIcon1 and click the triangle in the upper right corner to set the image.) 3, add a menu named "Exit" and "open" to ContextMenuStrip and associate it with the policyicon control (associated steps: set the ContextMenuStrip attribute of the policyicon control to the Name attribute value of the current ContextMenuStrip); 4. Add a series of events: public Form1 () {InitializeComponent (); // when the console is initially opened, the console icon cannot be visible. policyicon1.visible = false ;}///

/// Click the event in the exit menu ////// /// Private void exit ToolStripMenuItem_Click (object sender, EventArgs e) {this. Close ();}/// /// Open the menu and click event ////// /// Private void open ToolStripMenuItem_Click (object sender, EventArgs e) {policyicon1.visible = true; this. Visible = true; this. WindowState = FormWindowState. Normal; this. Activate ();}/// /// Click "minimize" to the tray event in the form window ////// /// Private void Form1_SizeChanged (object sender, EventArgs e) {if (this. WindowState = FormWindowState. Minimized) {this. Hide (); this. policyicon1.visible = true ;}}/// /// Click the tray icon, and the form window is normalized to display events ////// /// Private void policyiconw.mousedown (object sender, MouseEventArgs e) {if (e. button = MouseButtons. left & e. clicks = 1) {// display window this. visible = true; // normalize the window this. windowState = FormWindowState. normal; // activate the window to make the window focus this. activate ();}}/// /// Click "close" in the form window to minimize the event to the tray ////// /// Private void Form1_Closing (object sender, CancelEventArgs e) {// cancel closing window e. cancel = true; // minimize the window this. windowState = FormWindowState. minimized; // hide the window this. visible = false ;}/// /// Double-click the normal display window program of the tray ////// /// Private void policyicon1_mousedoubleclick (object sender, MouseEventArgs e) {if (e. button = MouseButtons. left & e. clicks = 2) {// display window this. visible = true; // normalize the window this. windowState = FormWindowState. normal; // activate the window to make the window focus this. activate ();}}

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.