Click here to Skip to main content
15,868,016 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.7K   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

 
GeneralVB .NET Pin
jadeboy17-Jan-03 1:03
jadeboy17-Jan-03 1:03 
Generalsome proplem Pin
chinadeer11-Jan-03 2:32
chinadeer11-Jan-03 2:32 
GeneralRe: some proplem Pin
Francesco Natali15-Jan-03 5:46
Francesco Natali15-Jan-03 5:46 
GeneralRe: some proplem Pin
Member 60381716-Dec-03 15:04
Member 60381716-Dec-03 15:04 
GeneralRe: some proplem Pin
User 116813211-Oct-04 11:28
User 116813211-Oct-04 11:28 
GeneralCool But... Pin
hooda14-Dec-02 11:34
hooda14-Dec-02 11:34 
Generalcool Pin
Jusin3-Dec-02 5:29
Jusin3-Dec-02 5:29 
Question.net menu? Pin
Roger Alsing3-Dec-02 3:10
Roger Alsing3-Dec-02 3:10 
AnswerRe: .net menu? Pin
Nicholas Naddaf3-Dec-02 8:12
Nicholas Naddaf3-Dec-02 8:12 
GeneralRe: .net menu? Pin
Kishorerc23-Dec-02 20:58
Kishorerc23-Dec-02 20:58 
GeneralRe: .net menu? Pin
kmaster17-Jan-03 15:48
kmaster17-Jan-03 15:48 
GeneralRe: .net menu? Pin
DavidNohejl26-Jun-04 11:04
DavidNohejl26-Jun-04 11:04 

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.