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)]
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)
{
base.OnSubscribeControlEvents(c);
CheckBox CheckBoxControl = (CheckBox)c;
CheckBoxControl.CheckedChanged += new EventHandler(OnCheckedChanged);
}
protected override void OnUnsubscribeControlEvents(Control c)
{
base.OnUnsubscribeControlEvents(c);
CheckBox CheckBoxControl = (CheckBox)c;
CheckBoxControl.CheckedChanged -= new EventHandler(OnCheckedChanged);
CheckBoxControl.MouseHover += new EventHandler(OnMouseHover);
}
public event EventHandler CheckedChanged;
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