c# 创建 windows 托盘图标及上下文菜单

using System.Windows.Forms;
using System.Drawing;

private NotifyIcon notifyIcon;
private void createNotify()
        {
            notifyIcon = new NotifyIcon();
            notifyIcon.Text = System.Windows.Forms.Application.ProductName;
            notifyIcon.Visible = true;
            ShowInTaskbar = false;
            notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath);

            var open = new System.Windows.Forms.MenuItem("显示");
            //open.Click += Open_Click;
            var hide = new System.Windows.Forms.MenuItem("隐藏");
            //hide.Click += Hide_Click;
            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(new System.Windows.Forms.MenuItem[] { open, hide });
            //notifyIcon.MouseDoubleClick += _notifyIcon_MouseDoubleClick;
        }

 

posted on 2021-10-04 08:03  空明流光  阅读(296)  评论(0编辑  收藏  举报

导航