工具箱中缺少用户控件

Jos*_*shS 6 .net c# winforms

背景:使用 Visual Studio 2015 的 C# WinForms 程序。

我的项目中有一个用户控制类。我的用户控件类称为“FocusControl”。我的项目包含默认的“Form1”。用户控件没有自动填充到我的工具箱中。

我的研究和无效解决方案的历史:

  1. 设置自动填充:
    • 自动填充已打开,我已关闭并重新打开解决方案和程序。
  2. 重建解决方案:
    • 做了很多次。我也尝试清理和构建。
  3. 检查用户控件的命名空间:
    • UserControl、窗体和项目的命名空间是相同的。
  4. 进入工具箱并右键单击“选择项目...”
    • 我不打算添加一个 DLL,也不希望创建一个。我想在我的项目中保持对 UserControl 的设计控制。
    • 注意:当我使用与我的 UserControl 相同的代码创建一个新的“Windows 窗体控件库”时,我可以构建它来创建 DLL。使用这个 DLL,我可以成功地将 UserControl 添加到我的工具箱中。但同样,我不想这样做。
  5. 我尝试通过“添加用户控件...”通过项目添加一个新的用户控件,并通过一个按钮使该 UserControl 变得简单。那也没有出现。

我发现了更激进的解决方案:

  1. 将 [ToolboxItem(true)] 添加到 UserControl。

    • 试过了,没用。
  2. 从应用程序数据中删除旧的工具箱文件,因为它们可能会损坏:请参阅此处:https : //weblogs.asp.net/javiervillarreal/visual-studio-not-showing-properly-the-toolbox-items

    • 试过了,没用。

我不知道如何搜索谷歌来解决这个问题。

研究网站:

  • 最相关: 我可以在不制作 DLL 的情况下使用同一项目中的 UserControl 吗?
  • 链接 3:http://www. 论坛。com/showthread.php?660017-Custom-controls-not-showing-up-in-toolbox
  • 链接 4:https://social.msdn。微软。com/Forums/en-US/887c0adc-0c26-4789-b563-46d294177eb6/cant-see-custom-control-in-toolbox?forum=csharpide
  • 加上其他几十个。以上三个是最相关的,没有帮助。

编辑添加代码:

用户控制 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)

Jos*_*shS 1

没有找到修复。

我开始了一个新项目,首先复制了用户控件并构建了解决方案。之后,我可以在工具箱顶部的“ProjectRaven Components”下看到 FocusControl。我只是将控件和代码从旧项目复制/粘贴回新项目。似乎正在发挥作用。

如果您使用新项目名称创建了新项目,请记住更改命名空间。