2016-11-24 69 views
1

背景:使用Visual Studio 2015的C#WinForms程序。用户控件从工具箱丢失

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

我的研究和unworking解决方案的历史:上

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

更彻底的解决办法,我发现:

  • [的ToolboxItem(真)]添加到该用户控件。

    • 试过了,没有工作。
  • 删除APP数据旧的Toolbox文件,因为他们可以去腐败: 在这里看到:https://weblogs.asp.net/javiervillarreal/visual-studio-not-showing-properly-the-toolbox-items

    • 试了一下,没有工作。
  • 我出什么就谷歌搜索来解决这个问题的想法。

    研究网站:

    • 最相关的:Can I use a UserControl from the same project without making a DLL?
    • 链接3:HTTP:// WWW。 vbforums。 com/showthread.php?660017-自定义控件未显示在工具箱中
    • Link4:https:// social.msdn。微软。 com/Forums/zh-CN/887c0adc-0c26-4789-b563-46d294177eb6 /不能看到自定义控制在工具箱中?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(); 
         } 
    

    用户控制设计 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() 
         { 
    

    Form1.cs的

    namespace ProjectRaven 
    { 
        public partial class Form1 : Form 
        { 
    
         string ipAddressCamera; 
    
         public Form1() 
         { 
          InitializeComponent(); 
    

    窗体设计 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() 
         { 
    
    +0

    你的用户控件的**父类**是什么? –

    +0

    你将不得不显示一些代码,否则任何答案将是纯粹的猜测。我用几种方法为我的项目添加了一个控件,并没有任何问题。 – JohnG

    +0

    我使用用户控件,form1和form1.designer中的代码编辑了最初的问题。我只是从命名空间抓到初始化。 – JoshS

    回答

    0

    找不到修复程序。

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

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

    0

    ,你可以把这个用户控件到自己的项目,并输出它作为一个DLL。然后从您的项目中引用此dll。

    +0

    项目符号4指出了这一点。我想保持我的项目中的用户控制,以便我可以编辑它。从我的研究中可以发现,但它不适合我。 – JoshS

    相关问题