Click here to Skip to main content
15,879,096 members
Articles / Programming Languages / C#

Improvement of the .NET Menu Style Class

Rate me:
Please Sign up or sign in to vote.
4.27/5 (17 votes)
14 Jan 20032 min read 210.9K   467   51   37
This is an improvement by Francesco Natali over an improvement by Sajith M of the "Visual Studio .NET Menu Style" by Carlos H. Perez

Sample Image - nicemenu.png

Introduction

With this new ".NET Menu Style" class, you can get a great menu with only few lines of code. You don't have to write a line of code for each menu item because your menu now will be AUTOMATICALLY updated! This is very useful, 'cause now you can still build and update your menu with the VS.NET tool, but at runtime you'll always have a new fresh .NET style menu. Another improvement is about the menu images, now you can use a simple imagelist to store your icon, and with a line of code and a simple trick (to add the index of the image near the text of the menu item), you'll get your image near your menu item.

I've updated this class, now you can use icons with context menu and search for a MenuItem at runtime with an easy function. Now you can also download a nice RTF file editor that uses the .NET style menu. This RTF file editor is still under development, however it's already a good example of C# programming.

Using the Code

You have to add:

C#
using Utility.NiceMenu;

and after the "InitializeComponent()" code:

C#
NiceMenu myNiceMenu = new NiceMenu();
myNiceMenu.UpdateMenu(this.nameofyourmainmenu, 
    new NiceMenuClickEvent(nameofyourclickfunction));

If you want to add some incons in your menu, you have to:

  • add an imagelist control in your form
  • add your icons in your imagelist control
  • add in your menu items the index of the icon in the first two characters. For example:
    • 00New
    • 01Open
    • 02Close
  • After the NiceMenu myNiceMenu = new NiceMenu(); code, you have to add this simple line of code:
C#
myNiceMenu.imgMenu = nameofyourimagelist; 

Points of Interest

There are a lot of comments with the code, so... enjoy!

History

This is an improvement by Francesco Natali over an improvement by Sajith M of the "Visual Studio .NET Menu Style" by Carlos H. Perez

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


Written By
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralGreat tool. Beware if you re using multiple context menues Pin
anton_fernando25-Jun-07 10:29
anton_fernando25-Jun-07 10:29 
GeneralConverting to Visual Studio 2005 ToolStripMenuItem Pin
Veeran Kutty31-Jan-06 7:38
Veeran Kutty31-Jan-06 7:38 
GeneralConvenient click handler for menu Pin
CoreyRIT6-Jan-06 7:58
CoreyRIT6-Jan-06 7:58 
GeneralRe: Convenient click handler for menu Pin
anton_fernando23-May-06 9:55
anton_fernando23-May-06 9:55 
GeneralAdding a Windows Form to a menu Pin
Jim Barber27-Aug-05 19:18
Jim Barber27-Aug-05 19:18 
AnswerRe: Adding a Windows Form to a menu Pin
illium31-Jul-06 18:45
illium31-Jul-06 18:45 
Generalsubmenu arrow Pin
SoTTo27-Jun-05 4:45
SoTTo27-Jun-05 4:45 
QuestionMC++ ? Pin
CppBeginner9-Oct-04 0:55
CppBeginner9-Oct-04 0:55 
QuestionEnabled works?? Pin
mpwt17-Sep-04 0:58
mpwt17-Sep-04 0:58 
Generalvery nice tool Pin
sherb13-Sep-04 2:19
sherb13-Sep-04 2:19 
GeneralRe: very nice tool Pin
Anonymous14-Apr-05 18:04
Anonymous14-Apr-05 18:04 
QuestionHow can I set the submenuItem's Checked Status? Pin
hanll4-Jul-04 22:34
hanll4-Jul-04 22:34 
AnswerRe: How can I set the submenuItem's Checked Status? Pin
hanll4-Jul-04 23:27
hanll4-Jul-04 23:27 
GeneralThanks Pin
sfalong25-Mar-04 2:46
sfalong25-Mar-04 2:46 
GeneralIcon resources Pin
PPPDev9-Jan-04 5:57
PPPDev9-Jan-04 5:57 
QuestionWhat does ModifyRegistry does? Pin
azusakt23-Oct-03 17:49
azusakt23-Oct-03 17:49 
QuestionMDIList feature lost? Pin
pingdee22-Oct-03 8:18
pingdee22-Oct-03 8:18 
GeneralHotkeyPrefix Pin
lagay8-Sep-03 12:53
lagay8-Sep-03 12:53 
GeneralContext Menu and CloneMenu Method Pin
marianod222-Aug-03 9:12
marianod222-Aug-03 9:12 
GeneralOffice 2003 Menu Style Pin
8MX10-Apr-03 10:48
8MX10-Apr-03 10:48 
GeneralRe: Office 2003 Menu Style Pin
Ray Cassick10-Apr-03 11:48
Ray Cassick10-Apr-03 11:48 
GeneralBad Code Pin
TemplMetaProg28-Mar-03 1:38
TemplMetaProg28-Mar-03 1:38 
Sizes are incorrect (Menu items are HUGE!). Top-level bar is incorrect. Icons are kinda dodgy. Can't someone get it right, please?

nous sommes les maitres
nous sommes les esclaves
nous sommes partout
nous sommes nul part
nous maitrisons les lettres noires Smile | :)

GeneralRe: Bad Code Pin
Stephane Rodriguez.28-Mar-03 1:58
Stephane Rodriguez.28-Mar-03 1:58 
GeneralEqual Menuitem Name Pin
mveiga23-Jan-03 16:37
mveiga23-Jan-03 16:37 
GeneralRe: Equal Menuitem Name Pin
lonelywind19826-Apr-06 17:33
lonelywind19826-Apr-06 17:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.