Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

    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);
           }
       }
   }

  • Leaders
Posted
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.
[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...