Click here to Skip to main content
Click here to Skip to main content

Navigation Menu for Windows forms (Outlook bar style)

By , 2 Apr 2007
 

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

About the Author

NinethSense
India India
Member
Praveen.V.Nair - aka NinethSense - PMP, Microsoft MVP - is a person with an abnormal passion for technology. 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/.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberS.Dimitrov13 Apr '13 - 11:17 
It works like a charm. Nice job. Thanks.
Questionerror in source codememberBilwani1 Jan '12 - 20:50 
plz send me complete code fahim_bilwani72@hotmail.com
Questionhow to use this control?membervenkat11125 Dec '07 - 23:01 
can you please tell me step by step process to use this control in mdi form?
 
please make it soon as early as possible..
Generalmissing source [modified]memberPete102422 Aug '07 - 22:41 
Hi, the source seems to be incomplete, i miss the ctrlMenuBar.Designer.cs file, probably also some resource and property file is needed to compile. The source of the demo would also nice to have! Smile | :)
 
Cheers! Pete
 

-- modified at 4:49 Thursday 23rd August, 2007
GeneralRe: missing sourcememberNinethSense23 Aug '07 - 19:26 
Sorry, I will update the source-zip file soon.
 
Till that time here is the ctrlMenuBar.Designer.cs code.
 
namespace BMT
{
    partial class ctrlMenuBar
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Component Designer generated code
 
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.panel1 = new System.Windows.Forms.Panel();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.AutoScroll = true;
            this.panel1.BackColor = System.Drawing.Color.Transparent;
            this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(148, 190);
            this.panel1.TabIndex = 3;
            // 
            // ctrlMenuBar
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackgroundImage = global::BMT.Properties.Resources.btnBgnd;
            this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.Controls.Add(this.panel1);
            this.Name = "ctrlMenuBar";
            this.Size = new System.Drawing.Size(148, 190);
            this.Load += new System.EventHandler(this.ctrlMenuBar_Load);
            this.ResumeLayout(false);
 
        }
 
        #endregion
 
        private System.Windows.Forms.Panel panel1;
    }
}

 
PraVeeN
blog.ninethsense.com/

General11membertehnn29 Apr '07 - 16:32 
11
GeneralRe: 11memberNinethSense29 Apr '07 - 18:24 
11?
 
PraVeeN
blog.ninethsense.com/

GeneralGoodmemberEhsan Golkar10 Apr '07 - 1:23 
to be continiue , is'n it?;)
GeneralRe: GoodmemberNinethSense15 Apr '07 - 19:58 
Yup Smile | :)
 
PraVeeN
blog.ninethsense.com/

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 2 Apr 2007
Article Copyright 2007 by NinethSense
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid