Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UserControl vs CustomControl in C# [duplicate]

What is the difference between UserControl and CustomControl in C# using WindowsForm?

like image 327
sree aneev Avatar asked Mar 08 '13 13:03

sree aneev


People also ask

What is the difference between user control and custom control in WPF?

When you have a rapid and fixed content in your UI, use UserControl . When you want to separate some basic functionality of your main view to some smaller pieces with reusability, use UserControl . When you want to use your control in different projects and each project may want to change the look, use CustomControl .

What is the difference between user control and Windows Form?

User controls are a way of making a custom, reusable component. A user control can contain other controls but must be hosted by a form. Windows forms are the container for controls, including user controls. While it contains many similar attributes as a user control, it's primary purpose is to host controls.

What is a UserControl?

The UserControl gives you the ability to create controls that can be used in multiple places within an application or organization.

What are differences between custom controls and user control in ASP.NET explain with suitable code?

User controls are custom, reusable controls, and they use the same techniques that are employed by HTML and Web server controls. They offer an easy way to partition and reuse common user interfaces across ASP.NET Web applications. They use the same Web Forms programming model on which a Web Forms page works.


1 Answers

There are custom and user controls for both windows applications and web applications. The windows application controls have a .cs extenstion.

In a very general sense a user control is easier to create. You can drag existing controls like textboxes, labels, etc on to the form. Custom controls are generally more difficult (time consuming) to create, but offer greater flexibility, customiseability, and integration.

The major difference in a nutshell is this:

A user control is made up of existing controls. It is also sometimes referred to as a composite control because of this fact. A typical example is a login form. The form and all of the logic is contained within this 'reuseable' user control.

A custom control is a control that you create. In windows forms this means overriding the OnPaint method as in your example above. Custom controls do not have the same level of design time support as user controls do (ie dragging and dropping existing controls, etc). Custom controls are generally thought of as reuseable components that can be added to the toolbox of visual studio, so they typically are not specific to your business or code.

Here is a link that goes into the different forms with some code examples: http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsCreatingControls.aspx

like image 53
Scott Sellers Avatar answered Oct 11 '22 20:10

Scott Sellers