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).

Toolstripitem
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.

+1 0

Responses

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

Post a comment