背景:使用 Visual Studio 2015 的 C# WinForms 程序。
我的项目中有一个用户控制类。我的用户控件类称为“FocusControl”。我的项目包含默认的“Form1”。用户控件没有自动填充到我的工具箱中。
我的研究和无效解决方案的历史:
我发现了更激进的解决方案:
将 [ToolboxItem(true)] 添加到 UserControl。
从应用程序数据中删除旧的工具箱文件,因为它们可能会损坏:请参阅此处:https : //weblogs.asp.net/javiervillarreal/visual-studio-not-showing-properly-the-toolbox-items
我不知道如何搜索谷歌来解决这个问题。
研究网站:
编辑添加代码:
用户控制 FocusControl.cs
namespace ProjectRaven
{
[ToolboxItem(true)]
public partial class FocusControl : UserControl
{
private const NumberStyles StyleDouble = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowLeadingSign;
private ThermalCamera _camera;
public FocusControl()
{
InitializeComponent();
}
Run Code Online (Sandbox Code Playgroud)
用户控件设计器 FocusControl.designer.cs
namespace ProjectRaven
{
partial class FocusControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
Run Code Online (Sandbox Code Playgroud)
表格 Form1.cs
namespace ProjectRaven
{
public partial class Form1 : Form
{
string ipAddressCamera;
public Form1()
{
InitializeComponent();
Run Code Online (Sandbox Code Playgroud)
表单设计器 Form1.Designer.cs
namespace ProjectRaven
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
Run Code Online (Sandbox Code Playgroud)
没有找到修复。
我开始了一个新项目,首先复制了用户控件并构建了解决方案。之后,我可以在工具箱顶部的“ProjectRaven Components”下看到 FocusControl。我只是将控件和代码从旧项目复制/粘贴回新项目。似乎正在发挥作用。
如果您使用新项目名称创建了新项目,请记住更改命名空间。