Click Taskbar Display-Hide toggle, context menu, snap close form event
Public partial class Frmmain:form {public Frmmain () {InitializeComponent (); #region Unregister public void Logout () {if (MessageBox.Show ("Confirm to exit? "," hint ", messageboxbuttons.okcancel) = = DialogResult.OK) {notifyicon1.visible = false; FormCollection FC = Application.openforms; if (FC! = NULL && FC. Count > 0) {foreach (Form window in FC) { Window. Hide (); }} cachehelper.currentusrname = ""; Cachehelper.currentroleid = 0; Frmlogin fl = new Frmlogin (); Fl. Show (); }} private void Logout login Toolstripmenuitem_click (object sender, EventArgs e) {Logout (); } #endregion #region Change password private void Change password Toolstripmenuitem_click (object seNDEr, EventArgs e) {frmchangepwd FCP = new Frmchangepwd (); Fcp. Show (); } #endregion private void Frmmain_load (object sender, EventArgs e) {} private void frm Main_formclosing (object sender, FormClosingEventArgs e) {if (MessageBox.Show ("Confirm to exit?") "," hint ", messageboxbuttons.okcancel) = = DialogResult.OK) {Logout (); } else {e.cancel = true; }} private void maximized Toolstripmenuitem_click (object sender, EventArgs e) {Showwin (); } private void Exits Toolstripmenuitem_click (object sender, EventArgs e) {Logout (); The private void Frmmain_sizechanged (object sender, EventArgs e) {if (this. WindowState = = formwindowstate.minimized) {Hidewin (); }} private void Notifyicon1_mouseclick (ObjeCT sender, MouseEventArgs e) {if (E.button = = mousebuttons.right) {Contextme Nustrip1.show (mouseposition.x, MOUSEPOSITION.Y); } else {Showwin (); }} #region hide the show form///<summary>///Hide Form///</summary> private Voi D Hidewin () {this.notifyIcon1.Visible = true; This. Hide (); }///<summary>///Show main form//</summary> private void Showwin () { if (Visible) {Hidewin (); } else {/////Note here The order is important, first show after the set State Show (); WindowState = Formwindowstate.normal; }} #endregion}
The above is the C # Tray program instance double-click the Display form, to minimize the contents of the tray, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!