Click here to Skip to main content
14,770,038 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have following objects: notifyIcon1 and contextMenuStrip1.
In the Properties of contextMenuStrip1, under Items, I added two Tool Strip Menu Items:
tsMenuSubscribe 
and
tsMenuUnSubscribe
.
I cannot find a click even for individual
Tool Strip Menu Items
.

The event I found is
ontextMenuStrip1_ItemClicked
.
It is not correct because this event is fired irrespective of the click on any Tool Strip Menu Item.
Hence, I need help in differentiating clicks on individual
Tool Strip Menu Item
.

What I have tried:

In below example, I am trying to use the sub menu options that do not work.
 
<pre> private void tsMenuSubscribe_Clicked(object sender, ToolStripItemClickedEventArgs e)
        {
            NCTBuddy n = new NCTBuddy();
            n.ButtonText = "Subscribe";
            n.Show();
           
        }
        private void tsMenuUnSubscribe_Clicked(object sender, ToolStripItemClickedEventArgs e)
        {
            NCTBuddy n = new NCTBuddy();
            n.ButtonText = "UnSubscribe";
            n.Show();
        }


And finally, this is the event that works but do not differentiate which item is clicked in the menu.

        private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
         
        }
Posted
Updated 22-Mar-17 2:19am

in Design mode -> right click on tsMenuSubscribe item -> properties -> events -> click event ( double click )
   
Comments
cluelessentity 22-Mar-17 6:36am
   
@Karthik
Thank you for your comment. But this ain't that simple.
This Menu is not like normal menu. It grows under ContextMenu linked to a NotifyIcon.
That means, on bottom right side of the screen, just next to the battery indicator of any windows laptop, near the clock I have my NotifyIcon. When I right click, it gives two menu items here.
Karthik_Mahalingam 22-Mar-17 6:51am
   
ok done that too, it works on right clicking the notifiy icon and clicking the menustrip item it went to the event.
cluelessentity 22-Mar-17 7:00am
   
@Karthik,

There is no right click I can make on the Tool Strip Menu Item.
Like we have collections in a combo-box, the same way I have Tool Strip Menu Items in ContextMenuStrip. So, when I select - right click on ContextMenuStrip, there is a property called Items. When I click on the (Collections) for the Items property, at that time I can add as many Tool Strip MEnu Items as I want but there is no right click on them. Also no events on them.
Karthik_Mahalingam 22-Mar-17 7:05am
   
so you want a right click on menustrip items?
am not getting clearly, if you could post a screenshot , it would be better
imgur.com
cluelessentity 22-Mar-17 7:06am
   
Nop.
I can right click on contextMenuStrip.
I want to click on the items under contextMenuStrip that are called Tool Strip Menu Items. And I need to provoke an event and do stuffs in that event when these items are clicked.
Karthik_Mahalingam 22-Mar-17 7:30am
   
you will have to map the click event to each items in tool strip menu items, which i have mentioned in the solution.
Karthik_Mahalingam 22-Mar-17 8:36am
   
Check this
http://oi64.tinypic.com/2gy1qtj.jpg
The solution is to mention events in the form load:
tsMenuSubscribe.Click += tsMenuSubscribeClick;
           tsMenuUnsubscribe.Click += tsMenuUnSubscribeClick;


And, describe them anywhere in the code:

private void tsMenuSubscribeClick(object sender, EventArgs e)
       {

           NCTBuddy n = new NCTBuddy();
           n.ButtonText = "Subscribe";
           n.Show();

       }
       private void tsMenuUnSubscribeClick(object sender, EventArgs e)
       {
           NCTBuddy n = new NCTBuddy();
           n.ButtonText = "UnSubscribe";
           n.Show();

       }
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900