背景:使用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