Click here to Skip to main content
15,884,298 members
Articles / Operating Systems / Windows

Rich OutlookBar in XP and Vista Style

Rate me:
Please Sign up or sign in to vote.
4.86/5 (84 votes)
31 Mar 2021MIT3 min read 371.5K   6.9K   295   115
Creating a rich OutlookBar in XP or Vista style
In this article, you will learn how to create a rich OutlookBar in XP or Vista style

Screenshot - NewScreenCapture.jpg

Introduction

I've always enjoyed using a control that behaves like the OutlookBar in Outlook. After testing and creating this, I knew that if I wanted other people to work intuitively with my programs, the OutlookBar control must look and work like the one in Outlook.

Needed Properties

The control must be functional and accessible during runtime, as well as in design mode. You can resize the control in design time, so you can choose which buttons will be displayed as large buttons. The buttons can be added and changed using a collection editor. During runtime, the DropDown icon opens a context menu where you can choose which buttons will be visible. You also can open a "Navigation Pane Options" form where you can reorder the buttons.

At runtime, mouse movements must cause the buttons to repaint if needed. There are different color schemes for hovering buttons. I need large buttons and small buttons, displayed in the correct order even after resizing the control. I also want to be able to set a button in a "not allowed" state. Depending on the user of your program, you can disable certain buttons. The difference between Allowed and Enabled is that with the Allowed property set to False, you cannot see the button.

Basic Structure

There are three classes in this control:

Class OutlookBarButton

This represents the instances of the separate buttons. No painting occurs in this class. The basic members of this class are:

  • Text: This is the text drawn on the button if it's in a large state. If the button is at the bottom of the control, a tooltip will be displayed with the text of the button.
  • Visible: When False, the button will not be visible in the control. You can change this value at runtime with ContextMenu using the DropDown icon.
  • Allowed: When False, this button will not be visible in the control. You cannot access this button at runtime, so you can prevent certain users from clicking a certain button.
  • Image: The image that will be displayed. It works best with a 24x24 icon or larger.
  • Rectangle: This is only accessible in the assembly. When the OutlookBar class calculates where to draw the buttons, it will give each button the rectangle that OutlookBar used to draw it. Thanks to this property, it's easy to find out which button is clicked or which button must be repainted using different colors.

Class OutlookBarButtonCollection

Representing the collection of buttons on the control, this inherits from CollectionBase. In the code, you just use the normal procedures to add or remove buttons to the control:

VB
Dim newButton as New Altea.OutlookBarButton
With newButton
    .Text="my button"
    .Visible=False
    .Image=My.Resources.myImage
End With
me.OutlookBar1.Buttons.Add(newButton)

Or using the overloaded constructor:

VB
Me.OutlookBar1.Buttons.Add(New Altea.OutlookBarButton("my button", 
    My.Resources.myImage))

Class OutlookBar

Inheriting from System.Windows.Forms.Control, this is the main class. You have a property called Renderer with two options: Office2003 and Office2007. In a future version, there will be a third option called Custom. You can select a button from the code:

VB
Me.OutlookBar1.Buttons("Journal").Selected = True

This class has the most events. Events such as MouseMove, MouseDown, MouseLeave, etc. will be handled in this class. The painting also happens in this class. OutlookBar will decide which ButtonState the buttons have depending on which user action has happened:

VB
Friend Enum ButtonState
    Passive
    Hovering
    Selected
End Enum 

The ButtonState will raise the Paint methods to use the correct colors and cursor. In the painting code, there will often be references to several rectangles. Here's an overview with this image:

Screenshot - CaptureStructure_edit.JPG

Conclusion

Try it, run it and tell me about it!

History

  • 10th February, 2007: Original version posted
  • 14th July, 2007: Reduced flickering, added custom rendering for colors and button height
  • 2nd August, 2007: Download updated

License

This article, along with any associated source code and files, is licensed under The MIT License


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

Comments and Discussions

 
GeneralRe: Saving your added buttons? Pin
Daniel Leykauf18-Jul-09 13:44
Daniel Leykauf18-Jul-09 13:44 
Hi,

Do not know if you still need a solution. I use the following way:

1. On appl. closing, I save the button texts to get an identifier and order of button (a better way would be to implement a button name instead):

Dim strButtons As String = ""
Dim l As OutlookBarButtonCollection = Me.OutlookBar1.Buttons
For i As Integer = 0 To l.Count - 1
    strButtons += l(i).Text & ";"
Next
My.Settings.NaviButtonsOrder = strButtons

My.Settings.Save()


2. On form load I call this sub to set the new order:

Private Sub setButtonOrder()
    Dim lButtons As New Queue(Of OutlookBarButton)
    Dim lButtonsN As New Queue(Of OutlookBarButton)
    Dim lstrButtons() As String = Split(My.Settings.NaviButtonsOrder, ";")

    'get buttons from saved list
    For i As Integer = 0 To lstrButtons.Length - 1
        For Each btn As OutlookBarButton In Me.OutlookBar1.Buttons
            If btn.Text = lstrButtons(i) Then
                If Not lButtons.Contains(btn) Then lButtons.Enqueue(btn) : Exit For
            End If
        Next
    Next

    'get all new buttons which were not in saved list
    For Each btn As OutlookBarButton In Me.OutlookBar1.Buttons
        If Not lButtons.Contains(btn) Then
            lButtonsN.Enqueue(btn)
        End If
    Next

    'clear current button list
    Me.OutlookBar1.Buttons.Clear()

    'add buttons in new order
    For i As Integer = 0 To lButtons.Count - 1
        Me.OutlookBar1.Buttons.Add(lButtons.Dequeue)
    Next

    'add new buttons at the end of the list
    For i As Integer = 0 To lButtonsN.Count - 1
        Me.OutlookBar1.Buttons.Add(lButtonsN.Dequeue)
    Next
End Sub


Not nice, but fits to my needs.
Cheers, Daniel.
AnswerHere's the C# version ... Pin
Angelo Cresta20-Aug-08 5:12
professionalAngelo Cresta20-Aug-08 5:12 
GeneralRe: Here's the C# version ... Pin
shuami9-Sep-08 20:03
shuami9-Sep-08 20:03 
GeneralRe: Here's the C# version ... Pin
mattdbuk21-Sep-09 1:37
mattdbuk21-Sep-09 1:37 
GeneralC# Version Pin
Bigdream8-Jun-08 3:21
Bigdream8-Jun-08 3:21 
GeneralC# Pin
razhia25-May-08 15:58
razhia25-May-08 15:58 
GeneralC# Pin
JCBBath15-May-08 4:10
JCBBath15-May-08 4:10 
GeneralSliding Pin
Bjaquila4-Apr-08 5:01
Bjaquila4-Apr-08 5:01 
GeneralForeColorHovering Pin
Jazza514531-Jan-08 2:55
Jazza514531-Jan-08 2:55 
Generalc# Pin
wedding1236-Jan-08 20:38
wedding1236-Jan-08 20:38 
GeneralLicence Pin
Bostjan Gajsler5-Dec-07 0:49
Bostjan Gajsler5-Dec-07 0:49 
GeneralRe: Licence Pin
Star Vega19-Jan-08 10:57
Star Vega19-Jan-08 10:57 
GeneralRe: Licence Pin
Noodles193220-Oct-08 6:00
Noodles193220-Oct-08 6:00 
GeneralRe: Licence Pin
Star Vega20-Oct-08 6:04
Star Vega20-Oct-08 6:04 
GeneralRe: Licence Pin
Graham Irons5-Nov-08 12:37
Graham Irons5-Nov-08 12:37 
GeneralC# Pin
Sk8tz20-Nov-07 22:50
professionalSk8tz20-Nov-07 22:50 
AnswerRe: C# Pin
kris.allberry23-Nov-07 3:11
kris.allberry23-Nov-07 3:11 
GeneralProblem with Newer Version Pin
kolag11-Nov-07 19:05
kolag11-Nov-07 19:05 
GeneralEating up too much CPU. Pin
User 45427181-Oct-07 2:33
User 45427181-Oct-07 2:33 
QuestionRight to Left support please Pin
dhamenha24-Sep-07 23:58
dhamenha24-Sep-07 23:58 
GeneralRight to left support Pin
Mickey Ekstein7-Sep-07 11:38
Mickey Ekstein7-Sep-07 11:38 
QuestiononCLick Event Pin
davidhoyle30-Aug-07 11:07
davidhoyle30-Aug-07 11:07 
QuestionFont size for buttons? Pin
bjswift28-Aug-07 6:29
bjswift28-Aug-07 6:29 
AnswerRe: Font size for buttons? Pin
bjswift28-Aug-07 6:47
bjswift28-Aug-07 6:47 
GeneralRe: Font size for buttons? Pin
Star Vega30-Aug-07 5:37
Star Vega30-Aug-07 5:37 

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.