Background: C# WinForms program using Visual Studio 2015.
I have a User Control class in my project. My user control class is called 'FocusControl'. My project contains the default 'Form1'. The user control is not being auto populated into my toolbox.
My history of research and unworking solutions:
More radical solutions I found:
Add [ToolboxItem(true)] to the UserControl.
Delete the old toolbox files from the App Data because they can go corrupt: See here: https://weblogs.asp.net/javiervillarreal/visual-studio-not-showing-properly-the-toolbox-items
I am out of ideas on what to search Google for to solve this problem.
Research websites:
Edit adding code:
User Control 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();
}
User Control Designer 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()
{
Form Form1.cs
namespace ProjectRaven
{
public partial class Form1 : Form
{
string ipAddressCamera;
public Form1()
{
InitializeComponent();
Form designer 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()
{
Some of the listed solutions helped me in the past, but they wont today (with a third party child control class). BUT I managed to get the plain UserControl inheritence back to the Toolbox by using it from code first, like so:
In the Constructor of that Form initialize the "hidden" CustomUserControl
CustomUserControl con = new CustomUserControl();
Controls.Add(con);
con.Dock = DockStyle.Fill;
Rebuild Solution (I started it once)
Hope it helps someone.
Make sure your usercontrol is Public and that both in the designer-generated code and your code-behind, it is declared "Public Partial Class MyControl"
No fix found.
I started a new project and copied the User Control in first and built the solution. After that I was able to see FocusControl under 'ProjectRaven Components' at the top of my toolbox. I simply copy/pasted the controls and code back from the old project to the new one. It seems to be working.
Remember to change the namespaces if you made a new project with a new project name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With