Windows Forms Control Library

• It’s a collection of user controls.
• If a user control is created in the application, it can be used or accessed within the same application. If the user control is created in the “Windows Forms Control Library”, that user control is accessible in any other windows applications.
• The user controls created in the “windows forms control library”, are called as “Global user controls”.

Implementation of User Controls:


 Create the “Windows Forms Control Library”:
 In Visual Studio, click on “File” – “New” – “Project”.
 In the “New Project” dialog box, select the project template as “Windows Forms Control Library”.
 Enter the name and location of the project.
 Click on OK.
 Then the new control library project will be created along a user control called “UserControl1”.
 Note: To add additional user controls within the same project, just click on “Project” menu and choose “Add User Control”.

 Design and Develop the User Control:
 Design the UI in the user control, by dragging the controls from the toolbox.
 Write the code in “Code window”. (User control also supports event handlers similar to forms).
 Build the project. Then “.dll” project will be created in the “bin\Debug” folder.

 Invoke the User Control:
 Create a new windows application project.
 Right click on the toolbox’s “General” tab, and select “Choose Items”.
 Select the dll file from “bin\Debug” folder.
 Click on OK.
 Then the user control name will be displayed in the toolbox automatically.
 To invoke the user control on a form, just drag it from the toolbox into the form designer.
 Then the control object will be created in the form.

Demo on WindowsFormsControlLibrary

Windows Forms Control Library Project Name: MyControlLibrary
Windows Application Project Name: MyControlImplementationDemo
User Conterols
MyUserControl.cs

private void btnAdd_Click(object sender, EventArgs e)
{
int n1 = Convert.ToInt32(txtFirstNo.Text);
int n2 = Convert.ToInt32(txtSecondNo.Text);
int n3 = n1 + n2;
txtResult.Text = Convert.ToString(n3);
}