Design Time Support for a Custom Tool StripItem

The real miracle is how easily your custom ToolStripControlHost can plug into the design-time ToolStrip architecture. All you need to do is carry out a few simple steps.

First, add a reference to the System.dll assembly. Next, import the System.Windows. Forms.Design namespace. Now you can use the ToolStripItemDesignerAvailability attribute to specify what types of ToolStrip-derived classes your custom item supports. Because you've derived from ToolStripControlHost, which doesn't appear at design time at all, the default visibility of your class is none. Here's a quick change that allows your custom ToolStripItem to be added to a ToolStrip or StatusStrip at design time:

[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)]

public class CheckTextBoxToolStripItem : ToolStripControlHost { ... }

Finally, just rebuild your application and click the Edit Items link in the ToolStrip smart tag. At the bottom of the list of options, you'll see your newly created class (see Figure 14-19).

Figure 14-19. Adding a custom ToolStripItem at design time

Once you add your custom ToolStripItem, you can configure it in the Properties window. All the design-time skills you learned in Chapter 13 still apply. That means you can use attributes to customize the default gear icon, add descriptions for your properties, control how property values are serialized, and so on.

This integration makes it effortless to create custom ToolStripItem objects with designtime integration for menus, toolbars, and status bars. In fact, this model is so easy and elegant, it's hard not to wish for something comparable to give you design-time support for custom items in other collection-base controls, like the TreeView and ListView.

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


  • Amanda
    How to enable toolstrip smart tag in VB?
    5 years ago

Post a comment