ToolboxControl in DotNetBar for Windows Forms (WinForms) displays multiple set of items categorized under toolbox groups and automatically provides drag and drop functionality for end users so they can start dragging and dropping items from toolbox. It also allows end-user to re-arrange items on toolbox by simply using drag and drop.

You can add new items to ToolboxControl either at design-time using design-time functionality in VS.NET or at run-time.

At design-time simply use ToolboxControl Tasks menu as shown below:

To add toolbox items to the toolbox group, select the group and use its Tasks menu to create new items:

Use Move Up and Move Down commands to move selected toolbox group or selected item within the list.

Each toolbox group is represented by ToolboxGroup object. Each ToolboxGroup contains instances of ToolboxItem objects added to the toolboxGroup.SubItems collection which represent items in the toolbox. toolboxControl.Groups collection holds all toolbox groups.

Selection

As each toolbox item is selected toolboxControl.SelectedItemChanged event is fired and SelectedItem property will return reference to currently selected item. ToolboxControl supports following selection modes as selected using SelectionMode property:

  • NoSelection – Indicates that no selection is performed as toolbox items are clicked
  • Single – Indicates that only single items at a time can be selected
  • Multiple – Indicates that multiple items can be selected by simply clicking the items. In this case SelectedItems collection will hold list of selected items. To select or deselect items using code use SetSelectedItem method.

By default as each toolbox group is selected it gets expanded to show its items and previously selected group gets collapsed. This behavior is controlled by ExpandSingleGroupOnly property.

Search

ToolboxControl has built-in search capabilities. toolboxControl.SearchBoxVisible property controls whether text-box which allows user to search the control is visible. SearchForEachWord property controls how search is performed.  It indicates whether search text when entered is split into separate words and items returned that match any of the words entered or whether whole phrase is used to match items.

Working From Code

Here is simple code to create new toolbox group and add items to it:

ToolboxGroup group=new ToolboxGroup("My Group");
group.LayoutOrientation = DevComponents.DotNetBar.eOrientation.Vertical;
group.ResizeItemsToFit = true;
group.MultiLine = false;
toolboxControl1.Groups.Add(group);
 
ToolboxItem item=new ToolboxItem("Item", "\ue80b", eSymbolSet.Material);
group.SubItems.Add(item);

Customizing Colors

Toolbox control colors are contained in Office2007ColorTable.StyleClasses collection. There are couple of style classes used by the control as specified below:

  • ElementStyleClassKeys.ToolboxControlKey – class with this key holds the border and background style for the ToolboxControl itself.
  • ElementStyleClassKeys.ToolboxGroupTitleKey – class under this key is used to style the toolbox group title.
  • ElementStyleClassKeys.ToolboxGroupTitleMouseOverKey – style for toolbox group title while mouse is over it.
  • ElementStyleClassKeys.ToolboxGroupExpandedTitleKey – style for title while group is expanded

ToolboxItem objects use same color table as standard buttons so they appear uniform throughout the app. You can set custom color tables for them as shown here.

Related posts:

  1. How to use Option Groups feature
  2. How to create Ribbon Tab Groups in DotNetBar for WinForms
  3. How To Add GalleryGroup to GalleryContainer
  4. How to Customize DateTimeInput, DoubleInput, IntegerInput and TextBoxX colors
  5. How to use SideBar control