C # minimize the WinForm window to the system tray code and determine the left and right mouse events,

Source: Internet
Author: User

C # minimize the WinForm window to the system tray code and determine the left and right mouse events,

1. Set the WinForm attribute showinTask to false.
2. Add the policyicon control policyicon1 to add an Icon for the property icon of the control policyicon1.
3. Add a form minimization event (you must first add an event reference ):

This. sizeChanged + = new System. eventHandler (this. form1_SizeChanged); // The above line refers to the reference private void Form1_SizeChanged (object sender, EventArgs e) {if (this. windowState = FormWindowState. minimized) {this. hide (); this. policyicon1.visible = true ;}}

4. Add a click icon event (you must first add an event reference ):
Private void policyicon#click (object sender, EventArgs e)
{
This. Visible = true;
This. WindowState = FormWindowState. Normal;
This. policyicon1.visible = false;
}
5. You can right-click policyicon to add a menu:
Drag a contextMenuStrip control into the main form and add a menu in NicontextMenu. In the ContextMenu action of notifyIcon1, select NicontextMenu as the context menu.

6. Determine the left and right mouse events

Click the yyicon control and enter the code.

// NotifyIcon1 mouse event click (for example, double-click Select double-click event) private void policyicon#mouseclick (object sender, MouseEventArgs e) {if (e. button = MouseButtons. left & e. clicks = 1) {// left} else if (e. button = MouseButtons. right & e. clicks = 1) {// right }}

 

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.