A Simple C# Toolbar Docking Framework
Translated by maninwest@Codeforge Author:Rogério Paulo @ Codeproject
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) _toolBarManager.AddControl(_toolBar1); // 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);
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.
File listTips: You can preview the content of files by clicking file names^_^
|AllowedBorders.cs||228.00 B||2004-09-04 01:50|
|DockLocation.cs||317.00 B||2004-09-03 12:43|
|ToolBarDockArea.cs||6.15 kB||2004-09-04 01:58|
|ToolBarDockArea.resx||5.20 kB||2004-08-31 15:07|
|ToolBarDockHolder.cs||10.67 kB||2004-09-04 02:42|
|ToolBarDockHolder.resx||5.20 kB||2004-09-01 15:53|
|ToolBarManager.cs||12.83 kB||2004-09-04 02:21|
- Page 1
- Total 1