• Windows窗体编程基础学习:使用 NotifyIcon 组件向任务栏添加应用程序图标


    1.在Windows项目中新加一个窗体myNotifyIcon

    2.在设计视图 通过工具箱
      向该Form加入NotifyIcon 和 ContextMenuStrip
      并查看确保窗体myNotifyIcon的ShowIcon属性设置为True

    3.通过notifyIcon1的属性对话框 设置相关内容 
      属性部分设置
      BalloonTipIcon:
      BalloonTipText:程序在后台运行
      BalloonTipTitle:提示
      ContextMenuStrip:contextMenuStrip1
      Icon:
      Text:这是程序的图标
      Visible:True

      事件部分
      双击MouseDoubleClick
      其示例代码如下 
      private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
      {
          this.Show();
      }
     
    4.通过contextMenuStrip1的属性对话框 设置相关内容
      编辑其Items
      加入如下菜单项
      myNotifyIconOpen(最大化)
          其单击事件的示例代码如下
          private void toolStripMenuItemOpen_Click(object sender, EventArgs e)
            {
                this.Show();         
            }
      myNotifyIconHide(隐藏)
          其单击事件的示例代码如下
          private void toolStripMenuItemHide_Click(object sender, EventArgs e)
            {
                //隐藏窗体
                this.Hide();
                //弹出气球显示
                this.notifyIcon1.ShowBalloonTip(30);        
            }
      myNotifyIconExit(退出)
          其单击事件的示例代码如下
          private void toolStripMenuItemExit_Click(object sender, EventArgs e)
            {
                this.strCloseReason = "EXIT";
                this.Close();           
            }
     
    5.在窗体myNotifyIcon属性对话框的事件栏
      选择并双击FormClosing
      其示例代码如下
      private void myNotifyIcon_FormClosing(object sender, FormClosingEventArgs e)
      {
          //strCloseReason是一个全局的私有变量
          //加上这个判断 为的是
          //点击窗体上的关闭按钮时 起隐藏窗体作用
          //点击notifyIcon1的菜单上的退出菜单项时 才关闭窗体
          if (string.IsNullOrEmpty(strCloseReason))
          {
              this.Hide();
              e.Cancel = true;
          }
      }

  • 相关阅读:
    leetCode算法题(一)
    node学习笔记1(http模块)
    mySql常用命令总结
    django学习遇到的问题解决方式
    WebSSH2 界面ssh(转载)
    垃圾回收策略学习总结
    5种数组扁平化方法
    冒泡、插入、选择、归并、快速排序
    手写ES6数组方法
    HTTP options预请求
  • 原文地址:https://www.cnblogs.com/freeliver54/p/698816.html
Copyright © 2020-2023  润新知