articles

Home / DeveloperSection / Articles / Creating and using Windows Forms Control Library in C#.Net

Creating and using Windows Forms Control Library in C#.Net

Creating and using Windows Forms Control Library in C#.Net

Anonymous User73670 29-Jul-2010

Creating user control

  Creating and using Windows Forms Control Library in C#.Net

To create User Control in C# select the “Windows Forms Control Library” icon from New Project Dialog Box.

Add some controls and add codes for the controls in User Control.

Example

Creating and using Windows Forms Control Library in C#.Net

 Code

private void btnColour_Click(object sender, EventArgs e)
        {
//this will change the color of form on which this control is placed.
           this.ParentForm.BackColor= Color.Red;
        }

Now once the control is created we need to build it in order to use it in other projects.

Using User Control in project

To use a user control in our project we need to add that control in the project. To add right-click on Toolbox and select “Choose Items”

Creating and using Windows Forms Control Library in C#.Net

A dialog box “Choose Toolbox Items” will appear. In that dialog box click the Browse button and select user control created earlier from the bin\debug folder of the user control project, then press Ok.

Creating and using Windows Forms Control Library in C#.Net

The user control will be added to the project toolbox.

Creating and using Windows Forms Control Library in C#.Net

Now we can use the user control. 

Example

Creating and using Windows Forms Control Library in C#.Net 

 Screenshot after Execution

Creating and using Windows Forms Control Library in C#.Net

Color of the form changes on button click without doing any coding in the current form. On the button click code of the user, control is executed.


Updated 28-Jun-2020
I am a content writter !

Leave Comment

Comments

Liked By