Click here to Skip to main content
15,879,844 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have three forms form1, form2 and form3,

but i am writing my code in another class

from that class i have five items item1, item2, item3, item4, item5

now by programming i want to add these items in form1 menu strip

how it will done i have done but in the same form it is clear

but i have to make in other form

You can do it of course. Instead of showing to you how to do it, I'll show you how to find a code sample.

First, ask yourself? What is adding menu items not programmatically? This is no such thing!

Even if you're working with designer, it simply generates essentially the same code you would do "programmatically". So, do a simple thing: add menu with items in designer and look at the generated code. Not just for menu — for all controls you need to generate programmatically.

Share this answer
Espen Harlinn 12-Jul-11 10:01am    
That's a very effective way to figure out how things fits together, my 5
Sergey Alexandrovich Kryukov 12-Jul-11 10:32am    
Simple, too. Thank you, Espen.
If you have three forms, why do you have to add the menu items programatically? Just do it in the designer and be done with it. I'm suggesting this because based on your original question, there's no need to add items in code.
Share this answer
kami124 11-Jul-11 5:58am    
ya you are right but i create one form by which i will send the name of an item and that nitem will be added to menu strip becouse that will done by end user for tis i want to create a function which will get the item as an argument and function defination will be to add the item in menu
Sergey Alexandrovich Kryukov 11-Jul-11 16:49pm    
Sorry, John, I disagree. There a many, many cases when one needs to generate a menu programmatically. Those cases are just more advanced. Sometimes the menu is generated out of meta-data, to make a single application having different functionality; sometimes you need to merge menus from plug-ins.
By that reason, I just provided an answer.
Assuming you already have a menu strip, just get the item you want to add a sub-menu to, and add the appropriately configured MenuItem objects.
Share this answer

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