C# 在winforms中将复选框插入toolstrip时出现问题
[带有虚假条目的下拉列表][2]我有一个几年前在Visual Studio 2010中创建的应用程序。它在应用程序的许多工具条中广泛使用复选框。它们都工作得很好 我最近开始在WS2019中创建一个新的应用程序,使用旧应用程序的大部分代码。除了toolstrips中的复选框外,其他都正常。当我尝试将复选框插入任何窗体toolstrips时,复选框不在下拉列表中。此外,列表中有一个名为CRToolStripTechBox的虚假项,它出现在预期复选框项的分隔符下方。这个虚假的输入实际上可以插入一个文本框(这是不需要的) 应该在任何toolstrips中插入复选框的类没有。但是,如果我创建一个新的测试解决方案并在类中复制,然后在测试表单中插入一个toolstrip,那么它工作得很好,并且不会出现虚假的CRToolStripTechBox 我已经搜索了整个应用程序,寻找虚假项目的实例,但什么也没有出现。我尝试创建一个新的解决方案,并从非工作版本复制了所有文件,但结果是一样的。虚假条目出现在下拉列表中,复选框不出现。我无法在任何表单的toolstrip中创建复选框C# 在winforms中将复选框插入toolstrip时出现问题,c#,checkbox,C#,Checkbox,[带有虚假条目的下拉列表][2]我有一个几年前在Visual Studio 2010中创建的应用程序。它在应用程序的许多工具条中广泛使用复选框。它们都工作得很好 我最近开始在WS2019中创建一个新的应用程序,使用旧应用程序的大部分代码。除了toolstrips中的复选框外,其他都正常。当我尝试将复选框插入任何窗体toolstrips时,复选框不在下拉列表中。此外,列表中有一个名为CRToolStripTechBox的虚假项,它出现在预期复选框项的分隔符下方。这个虚假的输入实际上可以插入一个文本
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;
这是我正在使用的代码
我已经搜索了整个应用程序,寻找虚假项目的实例,但什么也没有出现。我尝试创建一个新的解决方案,并从非工作版本复制了所有文件,但结果是一样的。虚假条目出现在下拉列表中,复选框不出现。我无法在任何表单的toolstrip中创建复选框
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;
我解决了这个问题。我在toolstrip中实现复选框的使用,而原始应用程序带来的解决方案中仍然存在许多错误。因此,在那时,新的应用程序将无法编译。 因此,我运行的构建失败了(我知道它会失败)。我假设管理所需复选框的创建并将其添加到toolstrip中的类只需像编译中的所有文件那样“保存”,一切都会很好。 当我清理了解决方案中大约50个错误时,我发现了结果。然后,我成功地运行了一次编译,系统完全按照要求运行。toolstrip上的下拉列表现在显示“复选框”,单击它将正确安装复选框。
感谢那些回答这个问题的人。一张图片真的会有帮助,我们无法根据这些信息回答这个问题-你需要缩小范围。我找不到在这里添加图片。当你回答你的问题时,有一个按钮工具栏,带有摄像头图标的按钮我试图通过拖放来包含图像,并执行以下操作“无法提交您的编辑”。请查看上面的错误,但上面没有错误。下拉列表如下所示。。。