如何为notifyicon制作菜单?

时间:2014-11-13 00:49:01

标签: c# notifyicon

所以..我已经google了,无处不在,我已经看到了不同的创造方式......

但到目前为止,我还没有设法制作单一的菜单。

所以我想问一下,如何创建一个notifyIcon菜单?...(详细解释,因为我对此很新)

哪种方式最好,我应该使用哪种...(到目前为止,人们似乎总是喜欢上下文,但我能找到的只是上下文,不确定它是否相同。)

目前我收到了一份表单,设置为visible = falsewindowstate minimizedshowintaskbar = false

这就是现在的全部。我想在扩大之前先拿菜单。

感谢您为此付出的时间和精力(不确定它是否制定得当)

编辑:我似乎设法制作一个菜单,但是如何让它“显示”在我的通知图标上,它是一个ContextMenu o_o

3 个答案:

答案 0 :(得分:1)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TrayTest.events
{
    public partial class TrayMenu : Form
    {
        public TrayMenu()
        {
            InitializeComponent();
            TrayMenuContext();
        }

        private void TrayMenuContext()
        {
            this.notify_icon.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip();
            this.notify_icon.ContextMenuStrip.Items.Add("Test1", null, this.MenuTest1_Click);
            this.notify_icon.ContextMenuStrip.Items.Add("Test2", null, this.MenuTest2_Click);
            this.notify_icon.ContextMenuStrip.Items.Add("Exit", null, this.MenuExit_Click);
        }

        void MenuTest1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        void MenuTest2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        void MenuExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

这对我来说很好。所以我只是把它留在这里,让其他人在它上面巅峰..(这是我的Form1,只是用一个不同的名字制作1,它在一个名为events的文件夹里面(有点为什么它有.events))

答案 1 :(得分:1)

"编辑:我似乎设法制作了一个菜单,但我怎么能做到这一点"出现"在我的通知图标上,它是一个ContextMenu o_o"

我相信您只能使用IDE将ContextMenuStrip分配给NotifyIcon。对于ContextMenu,您必须通过代码连接它。双击您的表单以获取Load()事件,并将其连接到那里:

    private void Form1_Load(object sender, EventArgs e)
    {
        notifyIcon1.ContextMenu = contextMenu1;
    }

答案 2 :(得分:0)

notifyIcon1->ContextMenu = gcnew System::Windows::Forms::ContextMenu();

System::Windows::Forms::MenuItem^ nI_Open_Item   = gcnew System::Windows::Forms::MenuItem("Open");
System::Windows::Forms::MenuItem^ nII_Close_item = gcnew System::Windows::Forms::MenuItem("Close");

notifyIcon1->ContextMenuStrip->Items->Add(status_Item);
notifyIcon1->ContextMenu->MenuItems->Add(nI_Open_Item);
相关问题