Click here to Skip to main content
11,429,687 members (72,871 online)
Click here to Skip to main content

Navigation Menu for Windows forms (Outlook bar style)

, 2 Apr 2007
Rate this:
Please Sign up or sign in to vote.
This article is about the creation of a user control which have the style like Outlook Express bar or DHTML Menu

Screenshot - scrnshot.jpg

Introduction

For one of my hobby projects, I wanted to use a 'Main Menu'. Rather than using the menu feature of windows I was thinking about some DHTML-style dropdown list menus. After searching I got many paid and free controls from which I only liked Infragestics controls. But in practice it is a big mess; I have to install the whole thing, my project is becoming too large and there is less performance. So I thought I must develop the user control of my dreams.

I would like to share my new user control with you so that you also can use it. It is easy to customize if you have knowledge in C#.

Using the code

Just download the code and add to your windows forms project. The menu items can be added to the control using:

ArrayList NavItems = new ArrayList();

ArrayList childNavItems = new ArrayList();
childNavItems.Add(new ctrlMenuBar.childNavItems("Leads", "mnuLeads"));
childNavItems.Add(new ctrlMenuBar.childNavItems("Project List", 
    "mnuProjectList"));
childNavItems.Add(new ctrlMenuBar.childNavItems("Development", 
    "mnuDevelopment"));

ctrlMenuBar.NavItem nv = new ctrlMenuBar.NavItem("Projects", "mnuProjects", 
    childNavItems, true);
NavItems.Add(nv);

In the following line: ctrlMenuBar.NavItem("Projects", "mnuProjects", childNavItems,true); the true is for telling the control whether it is the selected item or not. This parameter is optional. If you put true on more than one item, the last item will be the selected item.

For Rendering the menu you have to call the method:

ctrlMenuBar1.RenderMenu();

A typical menu initialization section will look like this:

private void frmMain_Load(object sender, EventArgs e)
{
    ArrayList NavItems = new ArrayList();

    ArrayList childNavItems = new ArrayList();
    childNavItems.Add(new ctrlMenuBar.childNavItems("Leads", "mnuLeads"));
    childNavItems.Add(new ctrlMenuBar.childNavItems("Project List", 
        "mnuProjectList"));
    childNavItems.Add(new ctrlMenuBar.childNavItems("Development", 
        "mnuDevelopment"));

    ctrlMenuBar.NavItem nv = new ctrlMenuBar.NavItem("Projects", 
        "mnuProjects", childNavItems, true);
    NavItems.Add(nv);
    childNavItems = new ArrayList();
    childNavItems.Add(new ctrlMenuBar.childNavItems("Client List", 
        "mnuClientList"));

    nv = new ctrlMenuBar.NavItem("Clients", "mnuClients", childNavItems);

    NavItems.Add(nv);

    childNavItems = new ArrayList();
    childNavItems.Add(new ctrlMenuBar.childNavItems("Developer List", 
        "mnuDeveloperList"));

    nv = new ctrlMenuBar.NavItem("Developers", "mnuDevelopers", 
        childNavItems);

    NavItems.Add(nv);

    childNavItems = new ArrayList();
    childNavItems.Add(new ctrlMenuBar.childNavItems("Reports","mnuReports"));
    childNavItems.Add(new ctrlMenuBar.childNavItems("Events", "mnuEvents"));
    childNavItems.Add(new ctrlMenuBar.childNavItems("Documents",
        "mnuDocuments"));
    nv = new ctrlMenuBar.NavItem("Utilities", "mnuUtilities", childNavItems);

    NavItems.Add(nv);

    ctrlMenuBar1.MenuItems = NavItems;
    ctrlMenuBar1.RenderMenu();
}

You can catch the button click events from the control to the method OnMenuSelection() For example:

private void ctrlMenuBar_OnMenuSelection(object sender, EventArgs e)
{
    Button btn = (Button)sender;
    label1.Text = "You clicked: " + btn.Name;
}

Behind the Screens

Behind the screens the User Control (ctrlMenuBar.cs) uses a main class ctrlMenuBar with two child classes: NavItem for parent menu items, and childNavItems for child menu items.

History

I am still making changes to the User Control. Whenever a major change is added, I will update this article. Thanks for trying my User Control.

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

Share

About the Author

Praveen Nair (NinethSense)
Architect ORION INDIA SYSTEMS
India India
Praveen.V.Nair - aka NinethSense - PMP, Microsoft MVP - is working as a Head of Technology and Architecture at Orion India Systems, Kochi, India. He has been playing with electronics from the age of 10 and with computers from the age of 14. He usually blogs at http://blog.ninethsense.com/.
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralMy vote of 4 Pin
Patrick Gatt1-Aug-13 3:46
memberPatrick Gatt1-Aug-13 3:46 
GeneralMy vote of 5 Pin
S.Dimitrov13-Apr-13 12:17
memberS.Dimitrov13-Apr-13 12:17 
Questionerror in source code Pin
Bilwani1-Jan-12 21:50
memberBilwani1-Jan-12 21:50 
Questionhow to use this control? Pin
venkat11126-Dec-07 0:01
membervenkat11126-Dec-07 0:01 
Generalmissing source [modified] Pin
Pete102422-Aug-07 23:41
memberPete102422-Aug-07 23:41 
GeneralRe: missing source Pin
NinethSense23-Aug-07 20:26
memberNinethSense23-Aug-07 20:26 
General11 Pin
tehnn29-Apr-07 17:32
membertehnn29-Apr-07 17:32 
GeneralRe: 11 Pin
NinethSense29-Apr-07 19:24
memberNinethSense29-Apr-07 19:24 
GeneralGood Pin
Ehsan Golkar10-Apr-07 2:23
memberEhsan Golkar10-Apr-07 2:23 
GeneralRe: Good Pin
NinethSense15-Apr-07 20:58
memberNinethSense15-Apr-07 20:58 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150428.2 | Last Updated 2 Apr 2007
Article Copyright 2007 by Praveen Nair (NinethSense)
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid