Custom ToolStripItem

The code snippet below shows how to add a custom ToolStripItem derived from ToolStripControlHost:

[DefaultProperty("Items")]
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip)]
public class MyToolStripCheckedListBox : ToolStripControlHost
{
    public MyToolStripCheckedListBox()
        : base(new CheckedListBox())
    {
        InternalListBox.CheckOnClick = true;
    }

    public CheckedListBox InternalListBox
    {
        get { return base.Control as CheckedListBox; }
    }
    
    [Localizable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]      
    public CheckedListBox.ObjectCollection Items
    {
        get { return InternalListBox.Items; }
    }
}

This entry was posted in WinForm. Bookmark the permalink.

Leave a comment