WinForm implementation minimized to the system pallet Method Example

Source: Internet
Author: User

This article describes the WinForm implementation to minimize the system tray method. Share to everyone for your reference. The specific analysis is as follows:

There's a control called NotifyIcon.

1, build a WinForm project, other operations skipped.

2, pull a NotifyIcon control, set the property visable to False, in the Text property on a random fill in some files.

3, the implementation of the form of the SizeChanged event, the code is as follows:

?

1 2 3 4 5 if (this. WindowState = = formwindowstate.minimized)//Determine whether to minimize {this. ShowInTaskbar = false; Do not appear in system taskbar notifyicon.visible = true; Tray icon Visible}

4, the implementation of the NotifyIcon control DoubleClick event, the code is as follows:

?

1 2 3 4 5 6 if (this. WindowState = = formwindowstate.minimized) {this. ShowInTaskbar = true; displayed in the system taskbar this. WindowState = Formwindowstate.normal; Restore form notifyicon.visible = false; Tray icon Hide}

Examples:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 This is the same as the same as the same as the same as the same as the same as the other, at the same (). private ContextMenu notifyiconmnu; #region minimized to taskbar///<summary>///minimize to taskbar </summary> private void Initializenotifyicon () {//define a MenuItem array and assign the array to the ContextMenu object menuitem[] Mnuitms = new Menuitem[3]; Mnuitms[0] = new MenuItem (); Mnuitms[0]. Text = "Display window"; Mnuitms[0]. Click + + new System.EventHandler (This.notifyicon1_showfrom); MNUITMS[1] = new MenuItem ("-"); MNUITMS[2] = new MenuItem (); MNUITMS[2]. Text = "Exit system"; MNUITMS[2]. Click + + new System.EventHandler (this. Exitselect); MNUITMS[2]. Defaultitem = true; Notifyiconmnu = new ContextMenu (MNUITMS); Notifyicon1.contextmenu = Notifyiconmnu; Add a set of ContextMenu objects to the tray program private void Notifyicon1_doubleclick (object sender, EventArgs e) {if (this.WindowState = = formwindowstate.minimized) {this. Show (); This. ShowInTaskbar = true; This. WindowState = Formwindowstate.normal; Notifyicon1.visible = false; } public void Notifyicon1_showfrom (object sender, System.EventArgs e) {if (this. WindowState = = formwindowstate.minimized) {this. Show (); This. ShowInTaskbar = true; This. WindowState = Formwindowstate.normal; Notifyicon1.visible = false; } public void Exitselect (object sender, System.EventArgs e) {//Hide the icon in the tray program notifyicon1.visible = false;//Shut down system this. Close (); This. Dispose (TRUE); #endregion private void Form_main_sizechanged (object sender, EventArgs e) {if (this. WindowState = = formwindowstate.minimized)//Determine whether to minimize {notifyicon1.visible = true; Hide (); This. ShowInTaskbar = false; Initializenotifyicon (); } }

I hope this article will help you with your C # programming.

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.