vbAccelerator Visual Studio Style ToolBox ListBar
Create tabbed bars of tools for your application
This control provides a full implementation of a Visual Studio-style List Bar
which holds lists of controls. Bars and items can be dragged around the control,
and items can be dragged, pressed or double-clicked to add the item to an object.
The ToolBox List Bar control has the following object hierarchy:
ToolBox ListBar Control Object Model
There are three main areas in using the control:
- Configuring the Control
- Adding and Removing Bars and Items
- Responding to Events
These will be covered in turn.
Configuring the Control
The control supports most of the basic properties of a VB control, including as BackColor, ForeColor,
Font, BorderStyle, Align and ScaleMode. These can be set at design time or runtime.
Icons for the items are sourced from an ImageList. To add an ImageList to the control, set the ImageList
property at run-time. If you're using a ComCtl32.DLL ImageList, then set this property to the hImageList
handle, otherwise set it to the ImageList control instance.
Adding and Removing Bars and Items
To build a bar, you need to start with the correct bottles. So, a bottle of Bombay Sapphire or Tanqueray 10,
some Grey Goose vodka, Absolut Citron, Makers Mark Bourbon, Myers's Dark Rum, Noilly Prat, Cointreau, Creme de Mure...
Oops, I appear to have got off
on the wrong subject. Actually adding, removing and accessing bars is done through the Bars collection
provided by the control
using the standard collection methods: Add, Remove, Item and Count. The only
things to note are that you must provide a unique Key for the bar and that
For..Each enumeration is not supported at this time.
The Add and Item properties return a cToolBoxBar object which can be used to set
the properties of the bar and move it around. Bar properties and methods are as follows:
Returns the owning control of this bar.
Gets/sets the caption of this bar
Gets/sets whether items are sorted alphabetically within the bar.
Gets/sets whether this bar is visible in the control or not.
Gets/sets a string value associated with the bar.
Gets/sets a long value associated with the bar.
Returns the index of the bar within the control.
Returns the key for this bar.
Gets a reference to the next bar along in the control. By default, this returns the next visible bar,
however if you set the optional bVisibleOnly parameter to False you can find the next bar along
regardless of visibility.
Same as NextBar but for the previous bar in the control.
Moves this bar to the next position along in the control.
Same as MoveNext but for the previous position.
Returns the cToolItemCollection of items within this bar, allowing you to add, insert, remove and find
items within the bar.
Returns the cToolItem which is selected within the bar.
Adding and removing items from bars is accomplished using the cToolItemCollection returned by
the Items property of the bar. This works in the same way as the cToolBoxBarCollection (and
again Keys are mandatory and the For..Each enumeration is not supported at this time). Note that item
keys must be unique across all bars, since you can shift an item between bars using drag and drop.
The Add and Item properties return a cToolItem object which can be used to set
the properties of the item and move it around. Bar properties and methods are as follows:
Returns the owning control of this item.
Returns the owning bar of this item.
Gets/sets the caption of this item.
Gets/sets the zero-based index of the icon within the ImageList associated with the control for this item.
Gets/sets whether this item is enabled or not.
Gets/sets whether this item is selected or not.
Gets/sets whether this item can be dragged or not.
Gets/sets a string value associated with the item.
Gets/sets a long value associated with the item.
Returns the index of the item within its bar.
Returns the key for this item.
Gets a reference to the next item along in the bar.
Same as NextItem but for the previous item in the bar.
Moves this item to the next position along in the bar.
Same as MoveNext but for the previous position.
Scrolls the bar containing this item if it is not visible in the control.
Responding to Events
The control raises the following events:
Raised when a bar is clicked by the user. Provides the bar that was clicked and the mouse button, shift state and coordinates
of the click.
Raised when a bar is double clicked by the user.
Raised when a bar is selected by the user. Note that this event does not fire if you select a bar in code using
the Selected property of a bar.
Same as BarClick except for an item. Note that this event is also raised if the user clicks a non-item area within
a bar, in which case the Item object will be Nothing.
Same as BarDblClick except for an Item.
Same as BarSelected except for an item.
The standard KeyDown event for the control. You can prevent the control from processing the key by modifying
the Key and Shift values. By default the control processes the Up, Down, PageUp, PageDown, Home and End keys.
The standard KeyPress event for the control.
The standard KeyUp event for the control.
Drag and Drop
When an item has the CanDrag property set true (which is the default), the user can drag the item within
the control itself or onto any control which supports drag and drop in the project. The control sets
customised Drag data which you can use to determine whether to allow the item to be dropped onto a particular
control. The formats set for an item are as follows:
The data contains an identifier to the item within the control. You can use the ItemFromDragData method
of the control to get a cToolItem object from this data, as follows:
Private Sub ctl_OLEDragDrop( _
Data As DataObject, _
Effect As Long, _
Button As Integer, _
Shift As Integer, _
x As Single, y As Single)
If (Data.GetFormat(tbbCfItemIdentifier)) Then
' Custom formats can only be obtained as a byte array:
Dim b() as Byte
b = Data.GetData(tbbCfItemIdentifier)
' Get the item itself:
Dim cT As cToolItem
Set cT = tbxLeft.ItemFromDragData(b)
' Now can use cT to work out whether to allow drag-drop
' or not.
The data contains the tag of the item within the control, as a byte array.
The caption of the item as a string.
That concludes the details of using the control. Another sample of using this control is
available demonstrating how to add the control to a pinnable
Visual Studio Style Tabs control
to create a full Visual Studio style Clipboard Ring.