[WPF] 托盘菜单的基本功能实现

直接来代码,自己留下一个印记 以后好看!

            NotifyIcon notifyIcon;
            ToolStripMenuItem mMain;
            notifyIcon = new NotifyIcon();
            notifyIcon.BalloonTipText = "共享快捷菜单.";
            notifyIcon.Text = "FLYFI[网络共享]";
            notifyIcon.Icon = ImageResources.NotifyIcon;
            ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
            mMain = new ToolStripMenuItem();
            mMain.Text = "开启共享(Start)";
            mMain.Image = ImageResources.Stoped;
            mMain.Click += mMain_Click;
            contextMenuStrip.Items.Add(mMain);

            ToolStripMenuItem tsm = new ToolStripMenuItem();
            tsm.Text = "重启共享(Rest)";
            tsm.Image = ImageResources.Exit;
            tsm.Click += Rest_Click;
            contextMenuStrip.Items.Add(tsm);

            ToolStripSeparator tSeparator = new ToolStripSeparator();
            contextMenuStrip.Items.Add(tSeparator);

            tsm = new ToolStripMenuItem();
            tsm.Text = "共享设置(Setting)";
            tsm.Image = ImageResources.Setting;
            tsm.Click += Setting_Click;
            contextMenuStrip.Items.Add(tsm);

            tsm = new ToolStripMenuItem();
            tsm.Text = "开机启动(Boot)";
            tsm.Image = ImageResources.Exit;
            tsm.Click += Boot_Click;
            contextMenuStrip.Items.Add(tsm);

            tSeparator = new ToolStripSeparator();
            contextMenuStrip.Items.Add(tSeparator);

            tsm = new ToolStripMenuItem();
            tsm.Text = "完全退出(All Exit)";
            tsm.Image = ImageResources.Exit;
            tsm.Click += AllExit_Click;
            contextMenuStrip.Items.Add(tsm);

            tsm = new ToolStripMenuItem();
            tsm.Text = "退出(Exit)";
            tsm.Image = ImageResources.Exit;
            tsm.Click += Exit_Click;
            contextMenuStrip.Items.Add(tsm);

            tsm = new ToolStripMenuItem();
            tsm.Enabled = false;
            contextMenuStrip.Items.Add(tsm);


            contextMenuStrip.BackColor = new System.Drawing.Color();

            notifyIcon.ContextMenuStrip = contextMenuStrip;

            contextMenuStrip.DropShadowEnabled = false;


            notifyIcon.Visible = true;
            notifyIcon.ShowBalloonTip(2000);
            notifyIcon.MouseClick += notifyIcon_MouseClick;


你可能感兴趣的:(C#,WPF,托盘菜单)