Click here to Skip to main content
13,355,018 members (58,999 online)
Click here to Skip to main content
Add your own
alternative version


80 bookmarked
Posted 9 May 2002

Rebar Control Wrapper in C#

, 9 May 2002
Rate this:
Please Sign up or sign in to vote.
C# Wrapper for the Microsoft Rebar Control
<!-- Download Links --> <!-- Article image -->

Sample Image - rebarcontrol.jpg

<!-- Add the rest of your HTML here -->


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.


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

Anthony Baraff
Web Developer
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralBest .NET Rebar implimentation on the net! Pin
Mr.Jinky24-Jan-09 9:53
memberMr.Jinky24-Jan-09 9:53 
GeneralFor .NET 2.0 / VS2005 users Pin
Patrick Sears8-Mar-07 7:49
memberPatrick Sears8-Mar-07 7:49 
QuestionHow to show chevron Pin
jefrubio28-Apr-06 1:45
memberjefrubio28-Apr-06 1:45 
The way to show chevrons in rebar band is adding RBBS_USECHEVRON constant in Style property of BandWrapper component. This can be do it by adding a new boolean field _useChevron to BandWrapper class, and modifing Style property as follows:
protected int Style
  get {
      style |= (int)RebarBandStyleConstants.RBBS_USECHEVRON;
    return style
  set {
    _useChevron = !((value & (int)RebarBandStyleConstants.RBBS_USECHEVRON)
       == (int)RebarBandStyleConstants.RBBS_USECHEVRON);

Also, it's very important to modify CreateBand method, adding the following line before creating the band (call to SendMessage):
rbBand.fMask |= (uint) RebarBandInfoConstants.RBBIM_IDEALSIZE;

To trap when a user clicks the chevron you will need to handle RBN_CHEVRONPUSHED to display a dropdown menu. Add a new case in WndProc of RebarWrapper class:
protected override void WndProc(ref System.Windows.Forms.Message m)
  if(_rebar != null && m.Msg == (int)WindowsMessages.WM_NOTIFY)
    NMHDR Notify = (NMHDR)Marshal.PtrToStructure(m.LParam,typeof(NMHDR));
    if(Notify.idFrom == 1)
        case ((int)WindowsNotifyConstants.RBN_CHEVRONPUSHED):
          this.NotifyChevronPushed(ref m);

and a new method:
private void NotifyChevronPushed(ref Message message)
  WindowsUtilities.NMREBARCHEVRON nrch = 
  int index = nrch.wID;
  if( (index >= 0) && (index < this._bands.Count ) && 
      ( this._bands[index] != null))
    Point point = new Point(nrch.rc.left, nrch.rc.bottom);
    this._bands[index].Show(this, point);

This method uses struct NMREBARCHEVRON. Add this struct to WindowsUtilities namespace in file RebarStructs.cs:
public struct NMREBARCHEVRON
  public NMHDR hdr;
  public int uBand;
  public int wID;
  public int lParam;
  public RECT rc;
  public int lParamNM;

Finally, you must create a public Show method in BandWrapper class:
public void Show(Control control, Point point) { }

This method is responsible of showing a popup context menu or toolbar that include items not shown in toolbar. By now, I'm implementing this method following the guidelines from
GeneralChevron and menubar (like IE) for Rebar Pin
vinod ms26-Oct-05 0:30
membervinod ms26-Oct-05 0:30 
GeneralAPI and struct definitions Pin
Christian Wikander19-Aug-04 23:42
memberChristian Wikander19-Aug-04 23:42 
GeneralRe: API and struct definitions Pin
mav.northwind31-Aug-04 21:21
membermav.northwind31-Aug-04 21:21 
GeneralRe: API and struct definitions Pin
Christian Wikander1-Sep-04 23:03
memberChristian Wikander1-Sep-04 23:03 
GeneralRe: API and struct definitions Pin
mav.northwind1-Sep-04 23:14
membermav.northwind1-Sep-04 23:14 
QuestionWidbey? Pin
coderforrent3-May-04 11:10
membercoderforrent3-May-04 11:10 
AnswerRe: Widbey? Pin
Anonymous14-Jan-05 2:13
sussAnonymous14-Jan-05 2:13 
Generalresize width in runtime with vertical rebar Pin
jax225-Mar-04 23:10
memberjax225-Mar-04 23:10 
QuestionPossible to make this a floating toolbar? Pin
artesano15-Sep-03 4:14
sussartesano15-Sep-03 4:14 
QuestionIs this control bug free? Pin
Melvin Ng12-Sep-03 0:49
memberMelvin Ng12-Sep-03 0:49 
GeneralMulti-band drawing is not correct when the winform is minimized and restored Pin
Radeon@lab-a26-Aug-03 21:13
memberRadeon@lab-a26-Aug-03 21:13 
GeneralRe: Multi-band drawing is not correct when the winform is minimized and restored Pin
Dem28-Oct-03 9:53
memberDem28-Oct-03 9:53 
GeneralFound a bug Pin
dacris20-Aug-03 21:04
memberdacris20-Aug-03 21:04 
GeneralYou could do this without API's Pin
Chris Pietschmann22-Jul-03 20:47
memberChris Pietschmann22-Jul-03 20:47 
GeneralRe: You could do this without API's Pin
Christian Wikander15-Aug-04 23:10
memberChristian Wikander15-Aug-04 23:10 
GeneralRe: You could do this without API's Pin
crpietschmann17-Aug-04 16:34
membercrpietschmann17-Aug-04 16:34 
GeneralRe: You could do this without API's Pin
Joe McConnell29-Jun-06 8:51
memberJoe McConnell29-Jun-06 8:51 
GeneralRe: You could do this without API's Pin
Mr.Jinky24-Jan-09 9:50
memberMr.Jinky24-Jan-09 9:50 
GeneralBand Positioning Pin
9ballrulz22-May-03 12:05
member9ballrulz22-May-03 12:05 
GeneralAbout CollectionEdit Pin
hbchen3316-May-03 21:39
memberhbchen3316-May-03 21:39 
Generalabout floating toolbar Pin
hbchen3316-May-03 21:35
memberhbchen3316-May-03 21:35 
GeneralExcellent work! Pin
Radeon@lab-a8-May-03 0:04
memberRadeon@lab-a8-May-03 0:04 

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.180111.1 | Last Updated 10 May 2002
Article Copyright 2002 by Anthony Baraff
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid