Click here to Skip to main content
13,410,919 members (33,662 online)
Click here to Skip to main content
Add your own
alternative version


154 bookmarked
Posted 3 Mar 2005

Cheat's Outlook Bar

, 3 Mar 2005
Rate this:
Please Sign up or sign in to vote.
An alternative "minimal-code" Outlook-style menu bar.

Sample Image - CheatsOutlookBar.jpg


I believe there's an old saying, "Clothes maketh the man", and this definitely applies to software too. No matter how clever and hard-working your applications are, if they're not wearing the latest well-designed clothes, people will think they are poorly written and out of date.

While working on a new project recently, I did a quick search on the web to see what the competition was up to. One of the features they had, which I didn't, was an Outlook-style menu bar, commonly referred to simply as an Outlook Bar. Deciding I wanted one too, I thought about writing my own. Searching the Code Project, I found two useful articles, Marc Clifton's An Outlook Bar Implementation, and Outlook XP bar by ACorbs. Both these articles were interesting and thought-provoking, and I downloaded each of them for a bit of a poke around, as one does!

I then found myself in a bit of a dilemma. I didn't want to simply copy someone else's code, but at the same time, I didn't want to spend hours and hours reinventing the wheel. I remembered a comment made by my manager at a previous job, many years ago. "What are we trying to do here? Achieve technical excellence, or get a job done?" Realising that Marc and ACorbs had done the former, I decided to go for the latter approach, and started doing some lateral thinking.

The eureka moment!

I proceeded to rummage around in the standard Windows Forms toolbox, and began to idly play around with splitters and panels. While doing this, I came across the Dock property, which specifies the justification for a control. In other words, does it attach itself to the top, bottom, left or right of its container, or does it fill all the available space. An idea occurred to me, so I added a Panel to my form, and added three Buttons to the panel. I set the Dock property of each button to Top, and "Lo!", I had created an Outlook Bar!

Well, almost...

Obviously, all I'd really done was stack three buttons one on top of the other, but they did resize themselves with the panel, which was decent of them. At this point, I realised I was going to have to write some code.

Some code

The only code I really needed is in the Click event handler for the buttons. They all share a common handler, as shown here:

void ButtonClick(object sender, System.EventArgs e)
    // Get the clicked button...
    Button clickedButton = (Button)sender;
    // ... and it's tabindex
    int clickedButtonTabIndex = clickedButton.TabIndex;

    // Send each button to top or bottom as appropriate
    foreach (Control ctl in panel1.Controls)
        if (ctl is Button)
            Button btn = (Button)ctl;
            if (btn.TabIndex > clickedButtonTabIndex)
                if (btn.Dock != DockStyle.Bottom)
                    btn.Dock = DockStyle.Bottom;
                    // This is vital to preserve the correct order
                if (btn.Dock != DockStyle.Top)
                    btn.Dock = DockStyle.Top;
                    // This is vital to preserve the correct order

    // Determine which button was clicked.
    switch (clickedButton.Text)
        case "Cars":

        case "Outlook Shortcuts":

        case "Zip Files":

        case "Miscellaneous":

                // Without this, the buttons will hide the items.

Basically, when any of the buttons on the panel is clicked, we save the clicked button and its TabIndex, then go through all the controls on the panel in turn. If it's a button, we check the TabIndex against that of the clicked button. If the TabIndex is greater, then the current button must be below the clicked one, so we send it to the bottom by setting its Dock to DockStyle.Bottom. If the TabIndex is lower, then the button goes to the top.

At this stage, I should point out that to make this work, it's vital that the TabIndices of the buttons are set at design time to the correct order. In the supplied example, the "Cars", "Miscellaneous", "Zip Files" and "Outlook Shortcuts" buttons have their TabIndex set to 1, 2, 3 and 4 respectively.

Back to the main plot. Having set the Dock properties to send the buttons up and down, I noticed that all was not well. If I had buttons 1, 2, 3 and 4 at the top, and I clicked button 1, then buttons 2 to 4 went to the bottom, but they ended up in reverse order, like this:

All is not well...

In an attempt to correct this, I tried a few things, such as walking the panel's controls in reverse order, and altering the TabIndex values "on the fly", but without success. I decided to research the Dock property on MSDN, which told me about the z-order, and explained that it could be controlled by the SendToBack and BringToFront methods of a control. It's explained here and here, much more clearly that I can do in a few words. Suffice to say, by calling the SendToBack method on each button after I docked it, preserved the order of the buttons.


The last piece of the jigsaw was another standard Windows Control, the ListView. I added this to the container panel, left its View property as the default LargeIcon, and set its Dock property to Fill, which means it will fill all the remaining space left by the buttons. I added some ImageLists, threw together some code to populate the ListView depending on which button was clicked, and I had a nice looking, functional Outlook bar, created from standard controls and a few lines of code. I then added a second ListView to provide some basic functionality to demonstrate that the menu bar worked.

Hopefully, this article will be of interest, and possibly show how sometimes it's useful to look at a problem from a few different angles before getting your code editor out!


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

Gary Perkin
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralCongratulations!!!! Pin
ewerton.478-May-13 8:49
memberewerton.478-May-13 8:49 
Questionauto hide Pin
hesam118-May-09 4:10
memberhesam118-May-09 4:10 
AnswerIts a great work Pin
algates002731-Jan-09 21:36
memberalgates002731-Jan-09 21:36 
GeneralExcellent work Pin
algates002731-Jan-09 21:34
memberalgates002731-Jan-09 21:34 
Questionvb net? Pin
jmarie9-Mar-07 10:39
memberjmarie9-Mar-07 10:39 
AnswerRe: vb net? Pin
loboeire30-Apr-07 12:08
memberloboeire30-Apr-07 12:08 
GeneralExcellent work! Pin
sekasi11-Sep-06 12:27
membersekasi11-Sep-06 12:27 
GeneralA problem Pin
zohre_j18-Jul-06 19:27
memberzohre_j18-Jul-06 19:27 
GeneralExcellent Pin
Ami Drutman20-Jun-06 4:31
memberAmi Drutman20-Jun-06 4:31 
QuestionSupport VB.NET?? Pin
nickong13-Jun-05 20:51
membernickong13-Jun-05 20:51 
GeneralProblem. Pin
eirikhm14-Mar-05 12:59
membereirikhm14-Mar-05 12:59 
GeneralRe: Problem. Pin
eirikhm14-Mar-05 13:10
membereirikhm14-Mar-05 13:10 
GeneralRe: Problem. Pin
Gary Perkin14-Mar-05 22:20
memberGary Perkin14-Mar-05 22:20 
GeneralRe: Problem. Pin
eirikhm15-Mar-05 0:51
membereirikhm15-Mar-05 0:51 
GeneralProblem with the samples Pin
benjymous10-Mar-05 4:56
memberbenjymous10-Mar-05 4:56 
GeneralRe: Problem with the samples Pin
nikster11-Mar-05 14:10
sussnikster11-Mar-05 14:10 
GeneralRe: Problem with the samples Pin
nikster11-Mar-05 14:17
sussnikster11-Mar-05 14:17 
GeneralThat's great,You are the man Pin
xiayan9-Mar-05 19:55
memberxiayan9-Mar-05 19:55 
GeneralNice! Pin
Adam Goossens6-Mar-05 0:10
memberAdam Goossens6-Mar-05 0:10 
GeneralZ-Order Pin
Mark Treadwell5-Mar-05 16:50
memberMark Treadwell5-Mar-05 16:50 
GeneralDoh Moment Pin
Gary Thom5-Mar-05 9:04
memberGary Thom5-Mar-05 9:04 
GeneralWonderfull ! Pin
Wouter van Vugt3-Mar-05 6:27
memberWouter van Vugt3-Mar-05 6:27 
GeneralTechnical excellence vs. getting the job done Pin
Marc Clifton3-Mar-05 4:19
protectorMarc Clifton3-Mar-05 4:19 
GeneralRe: Technical excellence vs. getting the job done Pin
WillemM7-Mar-05 0:52
memberWillemM7-Mar-05 0:52 
GeneralEloquent Solution Pin
Michael Potter3-Mar-05 4:16
memberMichael Potter3-Mar-05 4:16 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180225.1 | Last Updated 3 Mar 2005
Article Copyright 2005 by Gary Perkin
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid