A UserControl
is a Component
. You don't have to do anything extra to make it so.
If you create a new UserControl
within VS, it will automatically have the behavior you are seeking: drag from toolbox onto form, change its properties through the Properties panel.
This code creates functioning control that shows itself in the toolbox, and allows its properties to be changed.
public class TestUserControl : UserControl
{
public TestUserControl() {
InitializeComponent();
}
/// <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() {
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoEllipsis = true;
this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(231, 51);
this.label1.TabIndex = 0;
this.label1.Text = "This is a test user control";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// TestUserControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.Controls.Add(this.label1);
this.Name = "TestUserControl";
this.Size = new System.Drawing.Size(231, 51);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Label label1;
}
Maybe you could add your functionality to this class and see if it works then.