Now we are going to discuss how to create a custom control in C#. How dp we create and use them in a windows application ? As we know, a custom control is a control made by the user for a specific purpose and later we can use it in our application. In this article we
are going to see how we create and implement a custom window control.
Now we are going to make a Super Button by inheriting the Button class. It will
appear as a super button whenever we place the cursor on the button control. It
will appear just like a huge button in size. Whenever we mouse over on the
button it just change its size and becomes very large.

Let see how to create and use
it:

Step 1: Now take a Class
Library

First go to File->New->Project->Class Library

After that add some references

First right click on Class Library project reference property and add some references

Figure is given below how to add the library and after that write at the top of the Class library

Code Description : Here we are using a class named SupButton1
which inherits from the Button Class. Here we are making a property named IsSuper and by
default it will return true. [Description] it shows the description of the
property or event. [Category] shows the Category for which they are grouped.
Further we have to make a method named OnMousePlaced(EventsArgs e) which will
fire an event if the mouse is placed over the button and also increase it's
size by calling the size class of the drawing namespace and it's size become larger. Further the initialize component shows whatever the setting we have implemented
for a button that is all about the code.

Step 4: Now after doing
that all, Build the solution.

Step 5: Now open a new Window Forms Application project, as shown in the below figure.

Step 6: After opening the windows application, follow the sequence given below.

Now Right click on Solution Explorer and add Existing project

Now Right click on window application project and add a reference of the Classlibrary.dll. The below figure shows both projects

Step 7: Now you will see
that it will appear in to the toolbox component like below.

Step 8: Now you want to add
the control into the Toolbox then click on the any toolbox item and select
Choose item and add the .NET Component reference to the project . How it will
happen see in the figure given below:

Step 9: Now drag and drop
the sup Button Control to the window form and run it by pressing F5.

I am working as an associate writer with over 7 years of IT industry experience with different technologies. I hold Bachelor’s & Master’s degree in Computer Science. I started my journey with C# Corner wh... Read more