Introduction
This is a Visual Studio .NET like ToolBox control. It has all the animations
of the original plus some more. It is very customizable as you can see in the
snapshot. I copied the icons and tabs from the real ToolBox so it looks just
like the original.
The public methods
ToolBox(Size sz,int Button_Height,ContextMenu Menu)
- sz -Needed Specifies the size of the ToolBox.
- Button_Height -Optional Specifies the Height of the Buttons. If it is negative
the default value is used
- Menu -Optional Specifies the ListView`s context menu.
void AddTab(string Caption,int ImgIndex,ImageList ImgList)
void AddTab(ToolBoxTab Tab)
- AddTab adds another category to the ToolBox.
void AddItem(string Caption,int ImageIndex,int TabIndex)
void AddItem(ToolBoxItem Item, int TabIndex)
- AddItem adds an item to the specified Tab in TabIndex
ToolBoxTab GetTab(int Index)
- GetTab retrievs the ToolBoxTab object at the given index
int GetTabCount()
- Returns the number of Tabs.
bool RemoveTab(int Index)
- Removes the Tab specified in Index
bool RemoveItem(int TabIndex, int ItemIndex)
- Removes the Item specified at the given indexes.
void Compress()
- Makes the ToolBox to retreat.
void Expand()
- Makes the ToolBox to Expand.
void EndAllMovement()
bool ScrollUp()
- Scrolls the visible ListView up one item if possible
bool ScrollDown()
- Scrolls the visible ListView down one item if possible.
bool SetSize(Size sz)
- Modifies the size of the ToolBox.
These are the main methods except three that I will explain here:
public delegate void OnToolBoxClick(int TabIndex,int ItemIndex);
public delegate void OnToolBoxTabChanged(int TabIndex);
public delegate void OnToolBoxStateChanged(int State);
These delegate types are events that the ToolBox sends. For example if you
want to know when the current Tab is changed you do the following:
- Implement a method in your application like this:
void OnTBTabChanged(int TabIndex)
- In when you init the ToolBox you need to let the ToolBox know what function
to call when the event triggers:
tb.SetTabChangedDelegate(new ToolBox.OnToolBoxTabChanged(OnTBTabChanged));
Now your method will be called every time a new Tab is selected and receives
the Tab`s index that you can use with the GetTab method.
The SetDelegate methods are:
void SetClickDelegate(OnToolBoxClick OnTBxClick)
- This method sets the delegate method that is called when an item of the ListView
is clicked.
void SetTabChangedDelegate(OnToolBoxTabChanged OnTBTabChange)
- This method sets the delegate method that is called when a new Tab is selected
void SetStateChangedDelegate(OnToolBoxStateChanged OnTBStateChange)
- This method sets the delegate method that is called when the state of the
ToolBox changes. For example see the status Label in the Demo application.
The state of the ToolBox can be one of the following:
- ToolBox.States.Compressed = 1
- ToolBox.States.Compressing = 2
- ToolBox.States.Extended = 3
- ToolBox.States.Extending =4
enum States {Compressed=1,Compressing,Extended,Extending};
These are all the public methods.
The Properties
int DelayBeforeRetreat
- This gets/sets the amount of time in miliseconds before the ToolBox starts
to retreat when the mouse is no longer over it.
string DragDropSeparatorText
- This gets/sets the Separator text between the Tab text and the Item text when
Drag&Drop is performed
The default is ".".
SelectedTab
- Tihs gets/sets the selected Tab. If a new tab is specified it will act like
it was clicked by the user
int State
- This gets the state of the ToolBox. if you want to change it's state call
the Extend and Compress methods.
int TabAcceleration
- This gets/sets the Tab movement acceleration
Default it is 2.
int TabTime
- This gets/sets the time of the Tab movement in miliseconds.
int TimerInterval
- This gets/sets the refresh timer interval.
string TitleText
- This gets/sets the Title of the ToolBox.
Image ToolBoxImage
- This gets/sets the Image used on the left of the
ToolBox.
Adding a ToolBox to your application
This is very simple. Just do the following:
- Add a reference of the ToolBoxLib.dll.
- Add the following line of code at the beginning of your application:
using ToolBoxLib
- Declare a variable of type ToolBox.
- In the constructor, after the InitializeComponent(); set the Toolbox's
parameters.
Here is an example:
tb = new ToolBox(new Size(200,ClientRectangle.Height-28),18,ToolBoxContextMenu);
tb.Location = new Point(0,28);
tb.SetClickDelegate(new ToolBox.OnToolBoxClick(OnTBClick));
tb.SetTabChangedDelegate(new ToolBox.OnToolBoxTabChanged(OnTBTabChanged));
tb.SetStateChangedDelegate(new ToolBox.OnToolBoxStateChanged(OnTBStateChanged));
tb.Show();
this.Controls.Add(tb);
tb.BringToFront();