adding a checkbox to a toolstrip

fguihen

Junior Contributor
Joined
Nov 10, 2003
Messages
248
Location
Eire
Ive done a small tutorial online and created what i think is a checkbox that can be used on a toolstrip. the problem is i dont know how to add it to the tool strip. can anybody advise where to add this, and what code to use to add it. my ToolStripCheckBox code is shown below:

Code:
    class ToolStripCheckBox:System.Windows.Forms.ToolStripControlHost
    {
        public ToolStripCheckBox() :base (new System.Windows.Forms.CheckBox()) { }


        public CheckBox ToolStripCheckBoxControl
        {
            get
            {
                return Control as CheckBox;
            }
        }

        //expose checkbox.enabled as property
        public bool ToolStripCheckBoxEnabled
        {
            get
            {
                return ToolStripCheckBoxControl.Enabled;
            }
            set
            {
                ToolStripCheckBoxControl.Enabled = value;
            }
        }
        protected override void OnSubscribeControlEvents(Control c)
        {
            // Call the base method so the basic events are unsubscribed.
            base.OnSubscribeControlEvents(c);

           
            CheckBox ToolStripCheckBoxControl = (CheckBox)c;
            // Remove the event.
            ToolStripCheckBoxControl.CheckedChanged += new EventHandler(CheckedChanged);
        }

        protected override void OnUnsubscribeControlEvents(Control c)
        {
            // Call the base method so the basic events are unsubscribed.
            base.OnUnsubscribeControlEvents(c);

            
            CheckBox ToolStripCheckBoxControl = (CheckBox)c;
            // Remove the event.
            ToolStripCheckBoxControl.CheckedChanged -= new EventHandler(CheckedChanged);
        }

        public event EventHandler CheckedChanged;

        private void OnCheckChanged(object sender, DateRangeEventArgs e)
        {
            if (CheckedChanged != null)
            {
                CheckedChanged(this, e);
            }
        }
    }
 
Not having any experience writing tool strip controls, all I can offer is this one idea: You might want to use a tool such as Reflector to examine the ToolStrip controls designed by Microsoft. There may be a combination of attributes required in order for a ToolStripControl to be displayed in the list. For a quick and dirty approach, add a ToolStripButton to the tool strip, and change the control's type in the designer-generated code.
 
Back
Top