背景:使用Visual Studio 2015的C#WinForms程序。用户控件从工具箱丢失
我在我的项目中有一个用户控件类。我的用户控件类被称为“FocusControl”。我的项目包含默认的'Form1'。用户控件没有被自动填充到我的工具箱中。
我的研究和unworking解决方案的历史:上
- 设置自动填充:
- 自动填入是,我已经关闭并重新打开解决方案和程序。
- 重建解决方案:
- 完成很多次。我试图清理和建造。
- 检查用户控制的命名空间:
- 的命名空间是为用户控件和窗体和项目相同。
- 走进工具箱,然后右键单击“选择项...”
- 我并不希望增加一个DLL,也不希望创建一个。我想保持对我的项目中的UserControl的设计控制。
- 注意:当我使用与我的UserControl相同的代码创建一个新的“Windows窗体控件库”时,我可以构建它以创建DLL。有了这个DLL,我可以成功地将UserControl添加到我的工具箱中。但是,我不想这样做。
- 我尝试通过项目添加一个新的用户控件,通过项目添加用户控件,并使用户控件只需一个按钮即可。这也没有出现。
更彻底的解决办法,我发现:
[的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()
{
你的用户控件的**父类**是什么? –
你将不得不显示一些代码,否则任何答案将是纯粹的猜测。我用几种方法为我的项目添加了一个控件,并没有任何问题。 – JohnG
我使用用户控件,form1和form1.designer中的代码编辑了最初的问题。我只是从命名空间抓到初始化。 – JoshS