Home » Source Code » A Simple C# Toolbar Docking Framework

A Simple C# Toolbar Docking Framework

2015-01-09 21:24:31
The author
Download(s): 1
Point (s): 1 
Category Category:
工具条工具条 C SharpC#


Translated by  maninwest@Codeforge  Author:Rogério Paulo @ Codeproject
An example framework for toolbar handling, written in C#.
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 ToolBarManageras 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 ToolBarDockHolderuser control.

Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
AllowedBorders.cs228.00 B2004-09-04 01:50
DockLocation.cs317.00 B2004-09-03 12:43
ToolBarDockArea.cs6.15 kB2004-09-04 01:58
ToolBarDockArea.resx5.20 kB2004-08-31 15:07
ToolBarDockHolder.cs10.67 kB2004-09-04 02:42
ToolBarDockHolder.resx5.20 kB2004-09-01 15:53
ToolBarManager.cs12.83 kB2004-09-04 02:21
Sponsored links


(Add your comment, get 0.1 Point)
Minimum:15 words, Maximum:160 words
  • 1
  • Page 1
  • Total 1

A Simple C# Toolbar Docking Framework (38.23 kB)(10.17 kB)(11.17 kB)

Need 1 Point(s)
Your Point (s)

Your Point isn't enough.

Get 22 Point immediately by PayPal

Point will be added to your account automatically after the transaction.

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more Points


Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com


CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D