Implement the Tray (the taskbar icon is mutually exclusive to the tray icon), and the minimized click-to-click button separates when the taskbar icon is clicked.
Specific as follows:
1. Add the following controls to the form: MenuStrip menuStrip1, NotifyIcon ni_frmmain,timer timer1, Contentmenustrip cms_notify. Where the notify contains display, exit, and so on.
2, the implementation of the Code:
//Field://Current child formPrivate Currentform ChildForm =Null;//Status of the last formPrivateFormWindowState lastformstate;//Whether you clicked the Minimize buttonPrivateboolisminboxhited;//Within the constructorThis.ni_frmMain.Visible =False;#region Pallet-related codes#region Private method handles the display of a form hide close (exit)///<summary>///Show///</summary>PrivatevoidShowmainform () {This. Show ();This. WindowState =This. lastformstate;This. Activate ();This. ShowInTaskbar =True//Show form icon in taskbarThis.ni_frmMain.Visible =False//Hide icon in disc}///<summary>///Hide///</summary>PrivatevoidHidemainform () {This. Hide ();This. ShowInTaskbar =False//Show form icon in taskbarThis.ni_frmMain.Visible =True//Hide icon in disc}///<summary>///Close (exit)///</summary>PrivatevoidExitmainform () {if (MessageBox.Show ("Are you sure you want to exit the main program?","Confirm Exit", Messageboxbuttons.okcancel, messageboxicon.question, messageboxdefaultbutton.button2) = =DialogResult.OK) {This.ni_frmMain.Visible =False;This. Close ();This. Dispose (); Application.exit (); } }#endregion#region Right-click menu processing, Show hidden exit///<summary>///Show///</summary>///<param name= "Sender" ></param>///<param name= "E" ></param>Privatevoid Tsmi_notifyshow_click (Objectsender, EventArgs e) {showmainform ();}///<summary>///Hide///</summary>///<param name= "Sender" ></param>///<param name= "E" ></param>Privatevoid Tsmi_notifyhide_click (Objectsender, EventArgs e) {hidemainform ();}///<summary>///Exit///</summary>///<param name= "Sender" ></param>///<param name= "E" ></param>Privatevoid Tsmi_notifyexit_click (Objectsender, EventArgs e) {exitmainform ();}#endregion#region Private method when you double-click a pallet label, the form is displayedPrivatevoid Ni_frmmain_doubleclick (Objectsender, EventArgs e) {if (This. WindowState! =formwindowstate.minimized) {showmainform ();}}#endregionMinimize to pallet when #region point minimize buttonPrivatevoid Frmmain_sizechanged (Objectsender, EventArgs e) {if (This. WindowState! =formwindowstate.minimized) {This. ShowInTaskbar =True//The form icon in the taskbar displaysThis.ni_frmMain.Visible =False;This.lastformstate =This. WindowState; } }#endregionMinimize to pallet when #region form is closedPrivatevoid Frmmain_formclosing (Objectsender, FormClosingEventArgs e) {//E.cancel = true;//This. ShowInTaskbar = false;//form icon disappears in taskbar//This.ni_frmMain.Visible = true;//Hidetipform ();}#endregion#region icon blinking on off///<summary>///Open///</summary>PrivatevoidStartflicker () {this.timer1.Enabled =True;This. timer1. Start (); }///<summary>///close//</summary> private void Closeflicker () { This.timer1.Stop (); this.timer1.Enabled = false; This.ni_frmMain.Icon = TRUELORE.FARE.CLIENT.PROPERTIES.RESOURCES.TRUELORE0; } private int i = 0; private void Timer1_Tick (object sender, EventArgs e) {if (I < 1) {This.ni_frmMain.Icon = Truelore.Fare.Client.Propert ies. RESOURCES.TRUELORE0; i++; Return } else {this.ni_frmMain.Icon = Truelore.Fare.Client.Properties.Resources.truelore1; i = 0;}} #endregion #region The taskbar click on the form icon (Minimize | restore) and click the Minimize button private int wm_syscommand = 0x112; Private long sc_minimize = 0xf020; protected override void WndProc (ref Message m) {if (m.msg = = Wm_syscommand) {if (M.wparam.toint64 () = = Sc_minimize & & M.lparam.tostring ()! = "0")//m.lparam.tostring ()! = "0" indicates that the taskbar clicks on the form icon (minimized | restore) {hidemainform ();//Here the form is directly formatted//this . isminboxhited = true; Click on the Minimize button through the middle variable is not line return; }} base. WndProc (ref m); } #endregion #endregion
C #: Implement pallet (taskbar icon is mutually exclusive to tray icon)