Click here to Skip to main content
Licence CPOL
First Posted 27 Jan 2008
Views 47,759
Downloads 1,239
Bookmarked 74 times

Visual Studio 2005 ToolBox Clone

By | 3 May 2008 | Article
A simple clone of the Visual Studio 2005 toolbox using a standard treeview

Introduction

This control is a very simple Visual Studio ToolBox control clone. The control itself is just a owner drawn TreeView. Because it is based on a standard treeview, it supports only one style of the Visual Studio Toolbox - the list style.

Background

Many weeks ago, I needed a simple control that looks like the ToolBox in Visual Studio 2005. There're some controls on CodeProject doing stuff like this. But all these controls are too oversized for me. So I wrote my own one...

To create the look and feel of the toolbox, I have just overridden the OnDrawNode method. Depending on the node level, the OnDrawNode method will call the method for root items or sub items. As you can see, there're only two levels possible in this control. An item on level 0 will be a root item and drawn as the darker header items. All subitems (level > 0) will be drawn on level 1 as sub item.

Adding advanced tool tips to the toolbox was a little tricky, because the standard treeview does not support such tool tips. First I had to disable the standard tool tip functionality of the treeview like this:

private const int TVS_NOTOOLTIPS = 0x80;

/// <summary>
/// Disables the tooltip activity for the treenodes.
/// </summary>
protected override CreateParams CreateParams
{
  get
  {
    CreateParams p = base.CreateParams;
    p.Style = p.Style | TVS_NOTOOLTIPS;
    return p;
  }
}

After that, I have implemented a tool tip control which supports the advanced look and feel of the modern tool tips (also used in the original Visual Studio ToolBox).

Using the Code

The handling of this control is quite easy. If you have ever worked with the .NET TreeView control, you should not have any problems with it. But you have to set some properties at this time to let the control look like the Visual Studio ToolBox:

  • Set the DrawMode to OwnerDrawAll
  • Set the FullRowSelect to true
  • Set the HideSelection to false
  • Set the HotTracking to true
  • Set the ItemHeight to 20
  • Add an ImageList

Adding New Groups

// To support the custom tool tips, we
// have to add an enhanced node type to the toolbox.
ToolBox.VSTreeNode newGroup = new ToolBox.VSTreeNode();

newGroup.Text = String.Format("Sample Node {0}", toolBox1.Nodes.Count + 1);

toolBox1.Nodes.Add(newGroup);

Adding New Items to a Group

ToolBox.VSTreeNode newSubItem = new ToolBox.VSTreeNode();

newSubItem.Text =  String.Format("Sample SubItem {0}",
        toolBox1.SelectedNode.Nodes.Count + 1);

// Assuming, that a image list is set.
newSubItem.ImageIndex     = 0;
newSubItem.ToolTipCaption = "Look atg this!";
newSubItem.ToolTipText    = "This is an example ToolTip.";

// It's also possible to add a context menu to a node (root or subitem)
newSubItem.ContextMenuStrip = cmsExample;

// Add the new subitem to the toolbox.
toolBox1.SelectedNode.Nodes.Add(newSubItem);  

Updates

2008/04/03

  • Fixed bug with editing textbox which was displayed over the left blue border in edit mode
  • Fixed bug with wrong behaviour by clicking on the +/- of a group item
  • Added feature to display an item as disabled

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Popangler

Software Developer

Germany Germany

Member

Nothing to say about me..

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralNice control - but you might want to make a couple small changes PinmemberPRMan!!!12:52 8 Feb '10  
GeneralRe: Nice control - but you might want to make a couple small changes PinmemberPopangler5:25 9 Feb '10  
QuestionTreeview control with varying item height, Pinmemberprakash Invent0:36 1 Jul '09  
AnswerRe: Treeview control with varying item height, PinmemberPopangler5:26 9 Feb '10  
Generalvb.net Pinmembereallenpjcc17:32 21 Jun '09  
QuestionHow do i connect the attribute and data of the sql database to tree PinmemberMillaniaSnow0:50 3 Jun '09  
GeneralToolbox at design time in VS2008 PinmemberAngelo DeFusco6:33 21 Mar '09  
AnswerRe: Toolbox at design time in VS2008 PinmemberPopangler1:48 22 Mar '09  
Generalexpanding with reluctance... PinmemberPetru664:44 16 Oct '08  
GeneralPlease Column more more more PinmemberXess2:49 15 Jul '08  
GeneralMake a group bigger Pinmembercakirhal19:20 26 Jun '08  
GeneralRe: Make a group bigger PinmemberPopangler1:06 2 Nov '08  
QuestionCan i display a full Tree under each group member? Please help Pinmembershagunk653:32 14 Feb '08  
GeneralRe: Can i display a full Tree under each group member? Please help PinmemberPopangler20:40 14 Feb '08  
GeneralRe: Can i display a full Tree under each group member? Please help Pinmembershagunk658:06 15 Feb '08  
AnswerRe: Can i display a full Tree under each group member? Please help PinmemberPopangler1:02 16 Feb '08  
GeneralRe: Can i display a full Tree under each group member? Please help Pinmembershagunk6520:00 17 Feb '08  
GeneralRe: Can i display a full Tree under each group member? Please help Pinmembershagunk6517:12 24 Feb '08  
GeneralVery nice... PinmemberPawJershauge20:49 28 Jan '08  
AnswerRe: Very nice... PinmemberPopangler10:31 29 Jan '08  

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

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 3 May 2008
Article Copyright 2008 by Popangler
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid