• WinForm 程序托盘及右键退出


    //code by:博客园-曹永思

      private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                // 注意判断关闭事件reason来源于窗体按钮,否则用菜单退出时无法退出!
                if (e.CloseReason == CloseReason.UserClosing)
                {
                    e.Cancel = true;    //取消"关闭窗口"事件
                    this.WindowState = FormWindowState.Minimized;    //使关闭时窗口向右下角缩小的效果
                    this.notifyIcon1.Visible = true;
                    this.Hide();
                    return;
                }
            }

            /// <summary>
            /// 双击托盘打开主菜单
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                this.Visible = true;
                if (this.WindowState == FormWindowState.Minimized)
                {
                    this.WindowState = FormWindowState.Normal;
                }
            }

            /// <summary>
            /// 退出程序
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
            {
                this.notifyIcon1.Visible = false;
                this.Close();
                this.Dispose();
                Application.Exit();
            }

    /////没有这句的话,右键托盘图标,菜单是出不来的=============================
                notifyIcon1.ContextMenuStrip = contextMenuStrip1;

     欢迎转载,转载请注明出处,希望帮到更多人。

    .net URL重写例子

  • 相关阅读:
    DataGrid 的鼠标点击
    Menu菜单
    密码问题
    Combobox代码
    EndpointContracts
    the Differences between abstract class & interface in C#接口和抽象类的区别
    How to get MetaData on client side in WCF?如何在客户端获取WCF service的元数据
    Endpoint
    Assembly Essence 程序集深入探讨:程序集结构及部署
    EndpointBinding
  • 原文地址:https://www.cnblogs.com/yonsy/p/2766331.html
Copyright © 2020-2023  润新知