Developing Components in .NET
- Create Assembly/DLL which will contain components.
- Add New Project to current Solution as Class Library. Go to File > New > Project, or in Solution Explorer:
- Select Solution, right-click Add > New Project.
- Select “Class Library” from Templates (Project Types: Visual C# > Windows > Class Library).
- Create a Component.
- Add Component to current Class Library project. Go to Project > Add Component…, or in Solution Explorer:
- Select class library, then right-click, Add > Component.
- Modify the Component code. Eg:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Text; namespace libCustomApp { public partial class AppCustomizationConfig : Component { //----------------------------------------------------- // Fields //----------------------------------------------------- private string m_About = "Customization component for applications"; private string m_Company = "ACME, Inc."; private string m_Copyright = "Copyright © 2009, ACME"; private string m_Website = "http://www.acme.com"; private string m_Software = "Sample Software"; private string m_Custom = "My Software"; private string m_CCny = "001"; private string m_Mutex = "CompanySoftwareMutex"; //----------------------------------------------------- // Properties //----------------------------------------------------- public string About { get { return m_About; } set { m_About = value; } } public string Company { get { return m_Company; } set { m_Company = value; } } //----------------------------------------------------- // Methods //----------------------------------------------------- public AppCustomizationConfig() { InitializeComponent(); } public AppCustomizationConfig(IContainer container) { container.Add(this); InitializeComponent(); } } }
Reference Material
Component Hierarchy
System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.ScrollableControl System.Windows.Forms.ContainerControl System.Windows.Forms.UserControl
Source: Creating Custom .NET Controls in C#, http://www.ondotnet.com/pub/a/dotnet/2002/03/18/customcontrols.html?page=1, O'Reilly Windows Dev Center.