Click here to Skip to main content
Click here to Skip to main content

A Simple C# Toolbar Docking Framework

, 7 Sep 2004
Rate this:
Please Sign up or sign in to vote.
An example framework for toolbar handling, written in C#.

Sample Image - ToolBarDock.gif


This code snippet includes a simple framework for handling docking toolbars. This framework includes support for:

  • floating/docking bars
  • changing layout of docked bars
  • double-click to switch from docked to floating and back
  • show/hide bar
  • right-click for bar view menu
  • disabling docking using the control key
  • handles any kind of control, not just toolbars

The code runs on Windows XP and VS .NET 2002, but should work on most .NET environments.


The code was written while exploring the .NET framework. Although several toolbar handling implementations are available, I decided to have a go at writing my own. Nevertheless, I hope this article might be of use.

Using the code

Using the code is quite simple. Create a ToolBarManager object, giving it the form where the toolbars may be docked. This form would most likely be your application main form which would also keep the ToolBarManager as a member.

_toolBarManager = new ToolBarManager(this);

The ToolBarManager handles all UI operations on the toolbars and it is also the only class the programmer will access. Adding toolbars is performed by invoking the AddControl method. Different versions of this method are available to allow more control over the positioning of the new toolbar.

// Add toolbar (default position)
// Add toolbar (floating)
_toolBarManager.AddControl(_toolBar2, DockStyle.None);
// Add toolbar (left)
_toolBarManager.AddControl(_toolBar3, DockStyle.Left);
// Add toolbar (left, on the left of _toolBar3)
_toolBarManager.AddControl(_toolBar4, DockStyle.Left, _toolBar3, DockStyle.Left);
// Add control
_toolBarManager.AddControl(_dateTimePicker, DockStyle.Bottom);

Other methods are also available to access the toolbars being handled by the ToolBarManager. Their use is rather straightforward:

  • public ArrayList GetControls() - Returns the set of all the added controls.
  • public bool ContainsControl(Control c) - Returns true if the control is included.
  • public void ShowControl(Control c, bool show) - Shows or hides the control.
  • public void RemoveControl(Control c) - Removes the control.

Points of Interest

The docking behavior is performed by four ToolBarDockArea controls that are added and docked to all four sides of the form. These controls simply perform specific layout handling and automatic resizing according to the controls that are added or changed.

To achieve dragging, the ToolBarManager handles mouse events on all controls added via AddControl. During drags, the ToolBarManager checks, according to the mouse position, if the dragged control should be placed on its own form (floating) or on any of the dock areas.

The control key events are handled via PreFilterMessage.

The appearance of the toolbar (the floating frame and the gripper) are user drawn in the ToolBarDockHolder user control.


A history file with detailed information is included in the download, here is a summary.

Version 1.0:
First version by Rogério Paulo.

Version 2.0:
Updates by Martin Müller (aka mav.northwind):

  • ToolBarManager c'tor now takes a ScrollableControl and a Form so that you can define an independent docking region and do not always have to use the form. The form itself is still needed as owner of floating toolbars, though.
  • ToolBarDockHolder now has a new property ToolbarTitle, allowing you to specify an independent name for a floating toolbar. The default is still the control's Text, but the Control.TextChanged event will no longer modify the title.
  • ToolBarDockHolder now has a new property AllowedBorders where you can specify which borders the toolbar is allowed to dock to.
  • ToolBarManager.AddControl() now returns the newly added ToolBarDockHolder, so that it's properties can be modified. The example now includes a MainMenu
  • Modified the size calculation for vertical toolbars with separators


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

Rogério Paulo
Web Developer
Portugal Portugal
Rogério Paulo is a software engineer in the domain of industrial information technology since 1999.
He has been mainly involved in product development in the fields of SCADA, engineering toolsets, embedded systems, communication networks and industrial communication protocols.

Comments and Discussions

QuestionHow to have 'toolbar option' icon at the end of toolbar [modified] PinmemberSports Kuo7-Jul-10 17:28 
GeneralDoes not work in VS9 PinmemberKrischu3-Dec-09 1:20 
GeneralEventHandler Pinmemberh_r_sh14-May-09 16:15 
QuestionIs the demo old? Pinmemberhyping21-Aug-07 23:38 
JokeCongratulation Pinmemberemmanuel3016-Aug-07 4:07 
GeneralGUI Design in C# PinmemberHomup26-Jun-07 23:46 
Generala problem from XYZ PinstaffSean Ewington17-May-07 6:47 
GeneralToolbar manager for MDI Pinmemberarmina_200722-Apr-07 4:20 
QuestionUpdate to ToolStrip Pinmemberdanielku154-Mar-07 9:12 
GeneralToolbar Docking problem PinmemberMember #371959615-Jan-07 23:06 
GeneralUsing with UserControl's Pinmemberinfal7-Nov-06 6:28 
GeneralConversion of the ToolBar into a Toolbox control Pinmemberignaciordc19-Jul-06 6:25 
QuestionHow to Creat Navigator bar by C# Pinmembertriluu22-Jun-06 3:17 
Generalgood! Pinmemberqinshihuang19-Jun-06 5:56 
Generalme to get free C# teacher PinmemberHsen Ho15-Jun-06 17:44 
GeneralRe: me to get free C# teacher Pinmembermr_lasseter15-Jun-06 18:06 
QuestionPrevent close and context menu from showing? Pinmemberid10t24-Apr-06 4:36 
AnswerRe: Prevent close and context menu from showing? PinmemberHamid Qureshi24-Apr-06 19:34 
GeneralRe: Prevent close and context menu from showing? Pinmemberid10t25-Apr-06 3:54 
QuestionUsage of this code? Pinmembersm@va22-Mar-06 6:27 
AnswerRe: Usage of this code? PinmemberRogério Paulo26-Mar-06 8:23 
QuestionRe: Usage of this code? PinmemberDarkne_Se29-Jan-07 2:02 
AnswerRe: Usage of this code? Pinmembersinsel17-Jun-08 10:57 
GeneralDock Toolbar w.r.t Form PinmemberNCoder92142-Mar-06 18:10 
GeneralAdd multiple control to holder Pinmembervutle24-Feb-06 10:32 
GeneralRe: Add multiple control to holder Pinmembervutle24-Feb-06 10:53 
GeneralSave Load request PinmemberHyperbolix23-Feb-06 9:24 
GeneralRe: Save Load request Pinmemberjonh25-Feb-06 1:22 
GeneralRe: Save Load request PinmemberHyperbolix25-Feb-06 11:59 
GeneralRe: Save Load request PinmemberSorin Militaru22-Jun-06 23:20 
GeneralRe: Save Load request PinmemberSorin Militaru22-Jun-06 23:45 
GeneralRe: Save Load request Pinmemberjfk95521810-Jul-06 17:21 
GeneralRe: Save Load request Pinmemberchichu123418-Jul-06 17:12 
GeneralRe: Save Load request PinmemberJesua18-Dec-06 6:33 
GeneralRe: Save Load request Pinmemberopndesk8-Feb-07 18:49 
GeneralRe: Save Load request Pinmemberxu_xuthus5-Mar-07 22:00 
GeneralRe: Save Load request Pinmemberjonh6-Mar-07 9:09 
GeneralRe: Save Load request PinmemberMiss Litchi19-Mar-07 1:28 
GeneralRe: Save Load request Pinmemberjonh19-Mar-07 9:35 
GeneralRe: Save Load request PinmemberMiss Litchi29-Mar-07 7:24 
GeneralRe: Save Load request Pinmemberjonh29-Mar-07 8:49 
GeneralRe: Save Load request PinmemberVenki563-Oct-07 22:37 
GeneralRe: Save Load request Pinmemberjonh4-Oct-07 11:33 
GeneralRe: Save Load request Pinmemberlucia11022-Jul-08 4:42 
QuestionHow about a window (app) that docks to the Desktop??? PinmemberGSL33-Feb-06 16:07 
Generalrequest Pinmemberstalindaa8-Jan-06 12:38 
QuestionWonder full .... but if want to lock the tool bar how can i do that? PinmemberMasudur30-Dec-05 23:40 
QuestionDragging Problem PinmemberMohammad Hamed26-Dec-05 23:27 
QuestionCan it stay put when scrolling? PinmemberBenjH22-Dec-05 14:30 
AnswerRe: Can it stay put when scrolling? PinmemberRogério Paulo23-Dec-05 0:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411023.1 | Last Updated 8 Sep 2004
Article Copyright 2004 by Rogério Paulo
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid