• c#添加托盘图标右键后显示菜单选项


    1.拖入控件notifyIcon1到窗口

    2.拖入ContextMenuStrip到窗口

    3.选中notifyIcon1右键属性,右侧属性窗口栏找到ContextMenuStrip,选择contextMenuStrip1

     

    4.选择ContextMenuStrip,添加菜单选项

     右键图标:

     

     Form1主界面关闭按钮事件添加代码:

     void Min()
            {
                if (WindowState == FormWindowState.Normal && this.Visible == true)
    
                {
    
                    notifyIcon1.Visible = true;//在通知区显示Form的Icon
    
                    WindowState = FormWindowState.Minimized;
    
                   // Visible = false;
    
                    ShowInTaskbar = false;//使Form不在任务栏上显示
    
    
    
    
                }
            //    Close();
             //   GC.Collect();
            }
            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
    
                if (e.CloseReason == CloseReason.UserClosing)//当用户点击窗体右上角X按钮或(Alt + F4)时 发生           
                {
                    e.Cancel = true;
    
    
    
                    //notifyIcon1.Visible = true;//在通知区显示Form的Icon
    
                    //WindowState = FormWindowState.Minimized;
    
                    //Visible = true;
    
                    //ShowInTaskbar = false;//使Form不在任务栏上显示
                    Min();
    
                }
                
    
            }

    托盘控件的双击事件

     public void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    contextMenuStrip1.Show();
                }
    
                if (e.Button == MouseButtons.Left)
                {
                    this.Visible = true;
    
                    this.WindowState = FormWindowState.Normal;
                }
            }
    欢迎讨论,相互学习。 txwtech@163.com
  • 相关阅读:
    MYSQL-------安全等于<=>
    MYSQL-------转义简单说明
    Linux命令 sed
    长目录如何快速cd
    SQLAlchemy(增删改查)
    PostgreSQL主键约束混乱
    Python实现智能回复
    Python 腾讯云发送短信
    Python3 Twilio 发送短信
    Elasticsearch 多条件查询
  • 原文地址:https://www.cnblogs.com/txwtech/p/15471903.html
Copyright © 2020-2023  润新知