Click here to Skip to main content
15,881,709 members
Articles / Programming Languages / C#
Article

A VS.Net-like ToolBox

Rate me:
Please Sign up or sign in to vote.
4.84/5 (29 votes)
19 Sep 20023 min read 245.9K   10K   110   43
This is a Visual Studio .NET like ToolBox control with animation and drag and drop support.

Sample Image

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

C#
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.
C#
void AddItem(string Caption,int ImageIndex,int TabIndex)
void AddItem(ToolBoxItem Item, int TabIndex)
  • AddItem adds an item to the specified Tab in TabIndex
C#
ToolBoxTab GetTab(int Index)
  • GetTab retrievs the ToolBoxTab object at the given index
C#
int GetTabCount()
  • Returns the number of Tabs.
C#
bool RemoveTab(int Index)
  • Removes the Tab specified in Index
C#
bool RemoveItem(int TabIndex, int ItemIndex)
  • Removes the Item specified at the given indexes.
C#
void Compress()
  • Makes the ToolBox to retreat.
C#
void Expand()
  • Makes the ToolBox to Expand.
C#
void EndAllMovement()
  • Stops all Tab movement.
C#
bool ScrollUp()
  • Scrolls the visible ListView up one item if possible
C#
bool ScrollDown()
  • Scrolls the visible ListView down one item if possible.
C#
bool SetSize(Size sz)
  • Modifies the size of the ToolBox.

 

These are the main methods except three that I will explain here:

C#
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:

  1. Implement a method in your application like this:
    C#
    void OnTBTabChanged(int TabIndex)
  2. In when you init the ToolBox you need to let the ToolBox know what function to call when the event triggers:
    C#
    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:

C#
void SetClickDelegate(OnToolBoxClick OnTBxClick)
  • This method sets the delegate method that is called when an item of the ListView is clicked.
C#
void SetTabChangedDelegate(OnToolBoxTabChanged OnTBTabChange)
  • This method sets the delegate method that is called when a new Tab is selected
C#
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:

  1. ToolBox.States.Compressed = 1
  2. ToolBox.States.Compressing = 2
  3. ToolBox.States.Extended = 3
  4. ToolBox.States.Extending =4
C#
enum States {Compressed=1,Compressing,Extended,Extending};

These are all the public methods.

The Properties

C#
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.
C#
string DragDropSeparatorText
  • This gets/sets the Separator text between the Tab text and the Item text when Drag&Drop is performed
  • The default is ".".
C#
SelectedTab
  • Tihs gets/sets the selected Tab. If a new tab is specified it will act like it was clicked by the user
C#
int State
  • This gets the state of the ToolBox. if you want to change it's state call the Extend and Compress methods.
C#
int TabAcceleration
  • This gets/sets the Tab movement acceleration
  • Default it is 2.
C#
int TabTime
  • This gets/sets the time of the Tab movement in miliseconds.
C#
int TimerInterval
  • This gets/sets the refresh timer interval.
C#
string TitleText
  • This gets/sets the Title of the ToolBox.
C#
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:

  1. Add a reference of the ToolBoxLib.dll.
  2. Add the following line of code at the beginning of your application:
  3. C#
    using ToolBoxLib
  4. Declare a variable of type ToolBox.
  5. In the constructor, after the InitializeComponent(); set the Toolbox's parameters.

Here is an example:

C#
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();

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Romania Romania
I am 18 years old and I have programmed for one year in C++ and MFC.
I am now programming in C# and .NET Framework.

Comments and Discussions

 
QuestionNeed help Pin
Alitrix-kms4-Nov-14 19:01
Alitrix-kms4-Nov-14 19:01 
QuestionGRATITUDE Pin
4season12-Aug-14 1:31
4season12-Aug-14 1:31 
Questionhow to do same using VB Pin
Member 826548924-Sep-11 22:03
Member 826548924-Sep-11 22:03 
Hi,
This is one of the amazing thing i seen.
I am engineering student and am doing kind of project in vb and need such toolbox.
I am very much impressed by this stuff.
Can you please guide me how can i do the same in VB 2005?
Awaiting reply.
Thanks,
Ashay
GeneralCould you please select a license and attach to the project Pin
Coderider19-Jan-10 8:22
Coderider19-Jan-10 8:22 
GeneralNeed VB.NET Version Pin
kolag18-Nov-07 22:10
kolag18-Nov-07 22:10 
GeneralReally Excellent Pin
kolag31-Oct-07 0:58
kolag31-Oct-07 0:58 
QuestionHow can i move toolbar in the form? Pin
sangram120-Oct-06 1:55
sangram120-Oct-06 1:55 
GeneralMenu Pin
patshiva15-Sep-05 22:52
patshiva15-Sep-05 22:52 
Generaltoolbox docking Pin
vrushaliD10-Jan-05 18:37
vrushaliD10-Jan-05 18:37 
GeneralRightToLeft Pin
perspolis29-Oct-04 22:32
perspolis29-Oct-04 22:32 
GeneralProblem with XP Home Version Pin
CodingNDallas18-Feb-04 6:27
CodingNDallas18-Feb-04 6:27 
GeneralPanels instead of TreeList Pin
Vitolini13-Dec-03 20:19
sussVitolini13-Dec-03 20:19 
GeneralRe: Panels instead of TreeList Pin
funvill1-Aug-04 18:27
funvill1-Aug-04 18:27 
GeneralSelected Item Pin
Anonymous16-Jul-03 4:53
Anonymous16-Jul-03 4:53 
QuestionWhat happens if I resize the Toolbox? Pin
MikeI11-Jun-03 23:58
MikeI11-Jun-03 23:58 
AnswerRe: What happens if I resize the Toolbox? Pin
Iulian Serban12-Jun-03 4:15
Iulian Serban12-Jun-03 4:15 
GeneralComments Pin
Mr.FB20-Mar-03 6:24
Mr.FB20-Mar-03 6:24 
GeneralRe: Comments Pin
Iulian Serban20-Mar-03 6:38
Iulian Serban20-Mar-03 6:38 
GeneralRe: Comments Pin
Mr.FB21-Mar-03 9:00
Mr.FB21-Mar-03 9:00 
GeneralA Few Things Pin
Damage_Inc10-Mar-03 23:46
Damage_Inc10-Mar-03 23:46 
GeneralRe: A Few Things Pin
Damage_Inc11-Mar-03 3:36
Damage_Inc11-Mar-03 3:36 
GeneralExcellent example, comment about European programmer's Pin
BJavierto8-Jan-03 5:07
BJavierto8-Jan-03 5:07 
GeneralRe: Excellent example, comment about European programmer's Pin
Iulian Serban10-Jan-03 10:52
Iulian Serban10-Jan-03 10:52 
QuestionHow to keep an item selected? Pin
Jeffrey Ganping Chen14-Dec-02 18:52
Jeffrey Ganping Chen14-Dec-02 18:52 
AnswerRe: How to keep an item selected? Pin
Iulian Serban18-Dec-02 10:22
Iulian Serban18-Dec-02 10:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.