Click here to Skip to main content
15,896,111 members
Articles / Programming Languages / C#
Article

Rebar Control Wrapper in C#

Rate me:
Please Sign up or sign in to vote.
4.83/5 (21 votes)
9 May 20023 min read 272.5K   1.7K   81   35
C# Wrapper for the Microsoft Rebar Control

Sample Image - rebarcontrol.jpg

Introduction

When Microsoft released its .NET framework I’m sure that many of you were as surprised as I was that the Rebar or “Coolbar” control was not included. So, I fired up the Customize Toolbar window and added the Microsoft Coolbar Control (everyone knows that .NET works perfectly with COM). Maybe your results were different than mine, but I found the wrapped version to be completely useless. I couldn’t find any way to add child controls or attach them to bands. I briefly fiddled with COM interop, but that seemed to be a dead end. The end result was that I decided to implement a .NET Rebar control using the ll and native API calls.


First of several Disclaimers

The code is functional, but not all of the bugs have been fixed. There is a bunch of stuff that hasn’t been completed at this point (chevron functionality; certain properties; some Unicode stuff; a resizing bug; problems with MouseEnter, MouseHover and MouseLeave; comments in the source…), but I’ll periodically post updates along the way.


About the control Source Code

This is the first control I’ve developed using C#, and it’s also one of my first few C# projects. Please, keep that in mind when reviewing the code. Along the way I found that frequently there were better ways of doing things. In most (but not all) cases I fixed the code. There’s also a fair amount of unused code lying around. I’ll clean it up when I get a chance. That said, the source code may still be interesting to programmers who are looking for sample code covering one or more of the following areas: Windows API Calls, Control Attributes, the ControlDesigner class, CollectionBase class, Component class, Control class, CollectionEditor class and/or Windows Messages.


Using the RebarWrapper Control

Using the Rebar should be relatively self explanatory. Drop it into your form using the toolbox. The initial instance is created without any bands. To add bands, click on the Bands property of the RebarWrapper in the Property Browser. The Bands Collection Editor will allow you to Add, Remove and Edit the Rebar Bands. Each Band’s properties are controlled via a BandWrapper Component. As you add bands you’ll see them pile up in the component tray at the bottom of the Form Designer. Clicking on a band in the Rebar brings up the Rebar’s properties in the Property Browser. It does not select the BandWrapper Component. Use the dropdown at the top of the Property Browser, Band Collection Editor or the icon in the component tray to access the band’s property.

Each Band can act as the Parent for one control (although this can be circumvented by hosting several controls inside of a panel or other container control). Designate the control to be parented by editing the Child property of the band. For the control to behave properly, the child control must be parented by the RebarWrapper control. Use the MinHeight and MinWidth properties to size the band to fit the control it is parenting.


Conclusion and Final Disclaimer

Play around with the various properties, events and settings. I’d be very interested to hear about any improvements/fixes/adaptations. As I mentioned before, I’ll try to take care of bug fixes when I have the time and interest, but use this code at your own risk. Future versions may drop or add functionality, not be compatible with the old version, or never be developed at all. With all that said, enjoy.

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


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

Comments and Discussions

 
QuestionVertical Display? Pin
mikeyd2-Mar-03 3:13
mikeyd2-Mar-03 3:13 
AnswerRe: Vertical Display? Pin
Srinivasa Raghavan27-Mar-03 23:00
Srinivasa Raghavan27-Mar-03 23:00 
GeneralRe: Vertical Display? Pin
mikeyd28-Mar-03 16:13
mikeyd28-Mar-03 16:13 
GeneralRe: Vertical Display? Pin
Srinivasa Raghavan28-Mar-03 16:58
Srinivasa Raghavan28-Mar-03 16:58 
Generalstoring of position bands Pin
Trantor31-Oct-02 3:10
Trantor31-Oct-02 3:10 
GeneralMainMenu in Rebar Pin
Martijn Sneijders18-Oct-02 7:27
sussMartijn Sneijders18-Oct-02 7:27 
GeneralRe: MainMenu in Rebar Pin
Anthony Baraff18-Oct-02 7:58
Anthony Baraff18-Oct-02 7:58 
GeneralRe: MainMenu in Rebar Pin
Daniel Burby13-Dec-03 14:34
Daniel Burby13-Dec-03 14:34 
Questionhow to use the RebarWrapper Pin
haklae Kim30-Jul-02 19:51
haklae Kim30-Jul-02 19:51 

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.