zoukankan      html  css  js  c++  java
  • 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重写例子

  • 相关阅读:
    Qt中实现启动画面(延时过程中要加上app.processEvents())
    Qt5中生成和使用静态库
    360云后台(使用HTTP Cache服务器)
    lucene 从2.4.0—3.6.0—4.3.1版本升级
    从C++到Qt(命令行编译,讲解原理)
    赵伟国的逻辑
    windows 7 系统进程服务详解
    QT 4.87 changes
    海量小文件存储
    最大连续子序列乘积
  • 原文地址:https://www.cnblogs.com/yonsy/p/2766331.html
Copyright © 2011-2022 走看看