Click here to Skip to main content
14,086,787 members
Click here to Skip to main content
Add your own
alternative version


43 bookmarked
Posted 15 Apr 2006
Licenced CPOL

ToolStripControllerLabel that extends and shrinks ToolStrip control

, 2 Sep 2006
Rate this:
Please Sign up or sign in to vote.
ToolStripControllerLabel placeable on VisualStudio



ToolStrip control can host menus, items and user controls. The ToolStripItems can be placed and layouted on Visual Studio 2005. The ToolStrip items can be extended and customized by users and that are also placeable on Visual Studio.This article demonstrates the ToolStripControllerLabel that can collapse, extend and close ToolStrip control.


2006 Aug. 12, Updated

  • Previous toolStripItems, shrinker and closer were unified in a ToolStripControllerLabel
  • Icon images of the ToolStripControllerLabel were added.

(Author thanks Vainola Harri.)

2006 Sep. 3, Updated

  • Icons were modified.

How does it work ?


The demo application is a tiny application for demonstrating the ToolStripControllerLabel. (Demo application requires .NET Framework 2.0)

At first, click the Collapse icon icon of 'Header' label. You can see the tool strip shrinks and the icon changes to Expand button icon. Second, click the Expand button icon. Then, the tool strip should extend. This action is performed by the clicked ToolStripControllerLabel. Notice that the actions of 'Header' and 'Footer' are different. The header label changes the visibility of the items that are after it. The footer label changes visibility of the items that are before it.

Another functionality of this label is to 'Close' the tool strip control. Click the Close button icon. The tool strip should close. Actually, the instance of the tool strip is alive, so click the 'Show tool bars' button.

These all functionalities can be performed by a single class without coding on VisualStudio.

Use in ease


This class can be placed on your Windows form by using VS2005. You can use the item like other ToolStripItems by adding ToolStripControllerLabel project or adding reference to ToolStripControllerLabel.dll without any coding.

Previous version of ToolStripControllerLabel class displayed the icons by drawing rectangles and lines in the code. In such way, flexibility of the class was quite limited. One of readers (thanks,) suggested that the instance of icon images might improve this problem. So, I made three public properties of the icons. The images can be modified in VS2005.

Furthermore, the functionalities of 'collapse/expand items' and 'close items' were unified from the previous two classes. The functionality also can be easily chosen on VS2005.

Customizing properties in VS2005

Code in demo application

Since the ToolStripControllerLabel item can be placed on ToolStrip using Visual Studio, it really simplify the codes on Forms or Controls. Actually, demo application has no codes for the actions of collapsing, extending and closing. The code of Form1 has only 5 lines in order to show the ToolBars after it is hidden.

namespace CodeProject
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            toolStrip1.Visible = true;
            toolStrip2.Visible = true;

Code in ToolStripControllerLabel

The ToolStripControllerLabel is a subclass of ToolStripLabel. It overrides an OnClick event. OnClick call the following 'DoAction()' method.The following is a part of the DoAction() that changes visibility of the items.

// Collapse or extend

ToolStrip toolStrip = this.Owner;
int idx = toolStrip.Items.IndexOf(this);

if (ControllerType == StripControllerTypes.Header)
    // --- Header logic ---
    // This loop continues under the following conditions.
    // 1. There is a next item.
    // 2. The next item is not ToolStripControllerLabel
    while (idx + 1 < toolStrip.Items.Count &&
        toolStrip.Items[idx + 1].GetType() != typeof(ToolStripControllerLabel))
        toolStrip.Items[idx].Visible = !isCollapsed;
else // if (ControllerType == StripControllerTypes.Footer) 
    // --- Footer logic ---
    // This loop continues under the following conditions.
    // 1. There is a previous item.
    // 2. The previous item is not ToolStripControllerLabel
    while (idx - 1 > 0 &&
        toolStrip.Items[idx - 1].GetType() != typeof(ToolStripControllerLabel))
        toolStrip.Items[idx].Visible = !isCollapsed;



New ToolStrip functionality that collapses, expands or closes ToolStrip items can be implemented easily using Visual Studio.


If you create customized ToolStrip items, add attributes on the custom class. I obtained this information from a blog 'jfo's coding'by searching MSDN forum. It was really helpful. Sometimes customized items don't appear in the menu when using Visual Studio. In such case, re-build or re-open the Form contains the item.

    (ToolStripItemDesignerAvailability.ToolStrip |
public class ToolStripShrinker:ToolStripLabel
        public ToolStripShrinker() : base() { }


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


About the Author

Web Developer
Japan Japan
Iquoba is a developer of software for bioscience and biotechnology at Symplus corp., who started with BASIC or Z80 assembler when he was twelve.

You may also be interested in...


Comments and Discussions

GeneralQuery about new Option Pin
mananthan756-Jun-07 0:18
membermananthan756-Jun-07 0:18 
GeneralRe: Query about new Option Pin
Iquoba6-Jun-07 4:09
memberIquoba6-Jun-07 4:09 
GeneralExcellent Enhancement to the Toolstrip Pin
Jhoward18-Aug-06 6:23
memberJhoward18-Aug-06 6:23 
GeneralRe: Excellent Enhancement to the Toolstrip Pin
Iquoba18-Aug-06 16:19
memberIquoba18-Aug-06 16:19 
GeneralTypo Pin
The_Mega_ZZTer13-Aug-06 9:38
memberThe_Mega_ZZTer13-Aug-06 9:38 
GeneralRe: Typo Pin
Iquoba13-Aug-06 13:45
memberIquoba13-Aug-06 13:45 
NewsNew features Pin
Iquoba12-Aug-06 17:28
memberIquoba12-Aug-06 17:28 
GeneralToolStripHeader - Collapsible toolstrip Pin
Väinölä Harri1-Aug-06 19:54
memberVäinölä Harri1-Aug-06 19:54 
AnswerRe: ToolStripHeader - Collapsible toolstrip Pin
Iquoba2-Aug-06 6:07
memberIquoba2-Aug-06 6:07 
GeneralRe: ToolStripHeader - Collapsible toolstrip Pin
Iquoba12-Aug-06 20:10
memberIquoba12-Aug-06 20:10 
GeneralRe: ToolStripHeader - Collapsible toolstrip Pin
Väinölä Harri2-Sep-06 9:59
memberVäinölä Harri2-Sep-06 9:59 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190518.1 | Last Updated 2 Sep 2006
Article Copyright 2006 by Iquoba
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid