Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application created some years ago in Visual Studio 2010. It extensively uses a checkbox in many of the toolstrips in the app. All of them work perfectly.

I have recently started to create a new app in WS 2019 using much of the code from the old app. All is OK except the checkboxes in the toolstrips. When I try to insert a checkbox into any of the form toolstrips the checkbox is not available in the drop down. Furthermore there is a spurious item in the list called crtoolstriptectbox which appears below the separator where the checkbox item was expected. This spurious entry actually works inserting a textbox (which is not wanted).

The class that is supposed to insert a checkbox in any of the toolstrips at design time does not. however if I create a new test solution and copy in the class then insert a toolstrip in a test form it works perfectly and the spurious crtoolstriptectbox does not appear.

I have searched the whole app looking for an instance of the spurious item and notheing comes up. I have tried creating a new solution and copied all the files from the non working version but the result is the same. The spurious entry appears in the dropdown list and the checkbox does not appear. I cannot create a checkbox in the toolstrip in any of the forms.

here is the code...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Drawing;
namespace tt
{
    [System.ComponentModel.DesignerCategory("code")]

    [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip)]
    // [ToolboxBitmap(@"..\..\Images\CheckBox.bmp")]
    public class ToolStripCheckBox : ToolStripControlHost
    {

        public ToolStripCheckBox()
            : base(new CheckBox())
        { }

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

        public bool isChecked
        {
            get
            {
                return checkBoxControl.Checked;
            }
            set
            {
                checkBoxControl.Checked = value;
            }
        }

        protected override void OnSubscribeControlEvents(Control c)
        {
            // Call the base so the base events are connected.

            base.OnSubscribeControlEvents(c);

            // Cast the control to a MonthCalendar control.

            CheckBox CheckBoxControl = (CheckBox)c;

            // Add the event.

            CheckBoxControl.CheckedChanged += new EventHandler(OnCheckedChanged);
        }

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

            base.OnUnsubscribeControlEvents(c);

            // Cast the control to a MonthCalendar control.

            CheckBox CheckBoxControl = (CheckBox)c;

            // Remove the event.

            CheckBoxControl.CheckedChanged -= new EventHandler(OnCheckedChanged);
            CheckBoxControl.MouseHover += new EventHandler(OnMouseHover);
        }

        // Declare the DateChanged event.

        public event EventHandler CheckedChanged;

        // Raise the DateChanged event.

        private void OnCheckedChanged(object sender, EventArgs e)
        {
            if (CheckedChanged != null)
            {
                this.CheckedChanged(this, e);
            }
        }

        void OnMouseHover(object sender, EventArgs e)
        {
            this.OnMouseHover(e);
        }
    }
}


What I have tried:

I have tried recreating the application in a new solution and tried tests on the code above. All the tests and all the original application work but the new app will not create a checkbox in a toolstrip
Posted
Updated 15-Sep-19 21:37pm
Comments
[no name] 14-Sep-19 10:57am    
You created your own checkbox? Stick with what's given in Windows Forms if you want to have a life.

1 solution

I solved this problem. I was implementing the use of a checkbox in a toolstrip while there were still many errors in the solution brought over from the original application. Thus at that time the new app would not compile.
I was thus running a build that failed (I knew it would). I was assuming that the class that was managing the creation of the required checkbox and adding it into the toolstrip would just ‘save’ as all the files do in a compile and all would be good.
I found the result when I cleaned up the 50 or so errors sitting in the solution. I was then able to run a successful compile and ‘hey presto’ the system worked exactly as required. The dropdown list on the toolstrip now displays the ‘checkbox’ and clicking it installs a checkbox correctly. 
Thanks to those that responded to this question.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900