Assuming you want to create a re-usable Windows Forms Component, like a custom Button:
1. start a new C# Desktop Project of Type 'Class Library.
2. add references to the Project for 'System.Windows.Forms and System.Drawing
3. modify the Class Library code to look like this:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Dec29_FancyButton.cs
{
public class FancyButton: Button
{
private static Size defaultSize = new Size(100,30);
private static Color defaultBackColor = Color.White;
private static Color defaultForeColor = Color.Black;
private const string defaultText = "FancyButton";
public FancyButton()
{
Size = defaultSize;
BackColor = defaultBackColor;
ForeColor = defaultForeColor;
Text = defaultText;
}
public FancyButton(string text, Size bSize, Color backColor, Color foreColor)
{
this.Text = (text == String.Empty) ? defaultText : text;
this.Size = (bSize == Size.Empty) ? defaultSize : bSize;
this.BackColor = (backColor == Color.Empty) ? defaultBackColor: backColor;
this.ForeColor = (foreColor == Color.Empty) ? defaultForeColor: foreColor;
}
}
}
4. compile this to create the 'dll.
5. use the compiled dll like this:
a. start a new Project
b. add a reference to the compiled dll for FancyButton
c. put a 'using statement on the Form where you want to use the Component, then create and use instances of the component:
using Dec29_FancyButton.cs;
private void Form1_Load(object sender, EventArgs e)
{
FancyButton fb1 = new FancyButton();
this.Controls.Add(fb1);
fb1.Text = "number one";
fb1.Location = new Point(100, 100);
FancyButton fb2 = new FancyButton("number two",
Size.Empty, Color.Empty, Color.Empty);
this.Controls.Add(fb2);
fb2.Location = new Point(200,200);
}
6. You can mount the compiled 'dll in your ToolBox by:
a. create new Tab in the ToolBox ... or re-use one you've already created
b. select 'Choose Items'
c. add a reference to the 'dll