5,692,513 members and growing! (16,897 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Intermediate License: The Code Project Open License (CPOL)

Rich OutlookBar in XP and Vista style

By Star Vega

Creating a rich OutlookBar in XP or Vista style
VBWindows, .NET, .NET 2.0, WinXP, VistaVS.NET2003, VS2005, Visual Studio, Dev

Posted: 10 Feb 2007
Updated: 2 Aug 2007
Views: 94,767
Bookmarked: 167 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
Prize winner in Competition "Best VB.NET article of Jan 2007"
69 votes for this Article.
Popularity: 8.60 Rating: 4.68 out of 5
1 vote, 1.4%
1
0 votes, 0.0%
2
3 votes, 4.3%
3
8 votes, 11.6%
4
57 votes, 82.6%
5

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:

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:

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:

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:

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

  • 10/02/2007: Original version posted
  • 14/07/2007: Reduced flickering, added custom rendering for colors and button height
  • 02/08/2007: Download updated

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Star Vega



Occupation: Software Developer
Location: Belgium Belgium

Other popular VB.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 92 (Total in Forum: 92) (Refresh)FirstPrevNext
GeneralVisual C++ or C# Version PLEASE?memberCarlBenton18:08 20 Nov '08  
GeneralDoes anybody have the C# versionmemberAndy ufuris12:44 11 Sep '08  
GeneralSaving your added buttons? [modified]memberplanocz11:19 1 Sep '08  
AnswerHere's the C# version ...memberAngelo Cresta6:12 20 Aug '08  
GeneralRe: Here's the C# version ...membershuami21:03 9 Sep '08  
GeneralC# VersionmemberBigdream4:21 8 Jun '08  
GeneralC#memberrazhia16:58 25 May '08  
GeneralC#memberJCBBath5:10 15 May '08  
GeneralSlidingmemberBjaquila6:01 4 Apr '08  
GeneralForeColorHoveringmemberJazza51453:55 31 Jan '08  
Generalc#memberwedding12321:38 6 Jan '08  
GeneralLicencememberBostjan Gajsler1:49 5 Dec '07  
GeneralRe: LicencememberJan Geerinckx11:57 19 Jan '08  
GeneralRe: LicencememberNoodles19327:00 20 Oct '08  
GeneralRe: LicencememberStar Vega7:04 20 Oct '08  
GeneralRe: LicencememberGraham Irons13:37 5 Nov '08  
GeneralC#memberSk8tz23:50 20 Nov '07  
AnswerRe: C#memberkris.allberry4:11 23 Nov '07  
GeneralProblem with Newer Versionmemberkolag20:05 11 Nov '07  
GeneralEating up too much CPU.memberPJonDevelopment3:33 1 Oct '07  
QuestionRight to Left support pleasememberdhamenha0:58 25 Sep '07  
GeneralRight to left supportmemberMickey Ekstein12:38 7 Sep '07  
QuestiononCLick Eventmemberdavidhoyle12:07 30 Aug '07  
GeneralFont size for buttons?memberbjswift7:29 28 Aug '07  
GeneralRe: Font size for buttons?memberbjswift7:47 28 Aug '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 2 Aug 2007
Editor: Sean Ewington
Copyright 2007 by Star Vega
Everything else Copyright © CodeProject, 1999-2008
Web10 | Advertise on the Code Project