3
votes

So.. i've googled around and everywhere i've seen different ways of creating this..

But so far, i haven't managed to make a single working menu.

So i wanted to ask, how does one create a notifyIcon menu?.. (prefered explained in details, as i'm rather new to this)

which way would be best and which should i use.. (so far people seemed to like contextmenu overally, but all i can find is contextmenustrip, not sure if it's the same.)

Currently i got a form, set to visible = false, windowstate minimized, showintaskbar = false.

that's about all it is for now. i wanted to have the menu before going wider.

Thank you for your time and effort for this (not sure if it's formulated properly)

EDIT: i've seemed to manage to make a menu, but how would i make it "appear" on my notify icon, it's a ContextMenu o_o

3
Did you check this? codeproject.com/Tips/627796/… My first 5 seconds of google search. Please always specify what you found during your research - then we know what you have tried and what you haven't.Neolisk
Yes, i tryed that just in a little different way. forgot where i was it, but i did try that way.Komari Kamikita
Ok, you have tried something. Why don't you specify what exactly didn't work?Neolisk
probably just forgot to, in the frustration of trying to make it work.Komari Kamikita
In order for your question to be useful to the public, it needs to be well-written, part of it is a good description of the problem. Otherwise - "How to make a menu for notifyicon", the answer - "Here is some code that worked for me" is not verify useful. There are many other blocks of code on the internet which do the same. So your question+answer will unlikely stand out among those. Being specific is key to being noticed (by Google and other sources). Please consider this for your other questions. Thanks.Neolisk

3 Answers

7
votes
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();
        }
    }
}

This worked fine for me. So i'll just leave it here, for other to take a peak at it.. (this is my Form1, just made 1 with a different name, and it's inside a folder named events (kinda why it has that .events))

2
votes

"EDIT: i've seemed to manage to make a menu, but how would i make it "appear" on my notify icon, it's a ContextMenu o_o"

I believe you can only assign a ContextMenuStrip to the NotifyIcon using the IDE. For a ContextMenu, you'd have to wire it up via code. Double click your Form to get the Load() event, and wire it up in there:

    private void Form1_Load(object sender, EventArgs e)
    {
        notifyIcon1.ContextMenu = contextMenu1;
    }
0
votes
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);