Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control vs UserControl in WinForms?

What is the difference between a Control and a UserControl in .NET WinForms? I want to create a custom control, but which one should I inherit from? I've always used Control in the past without any issues, but is the "recommended" way of creating a custom control?

like image 812
Jon Tackabury Avatar asked May 28 '09 14:05

Jon Tackabury


People also ask

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 the difference between custom and user control?

CustomControl is a loosely coupled control w.r.t code and UI while UserControl is a tightly coupled control w.r.t code and UI. When using CustomControl UI can be changed in different projects but for a UserControl UI is fixed and can't have different looks in different project.

What are the controls of Windows form?

Windows Forms controls are reusable components that encapsulate user interface functionality and are used in client-side, Windows-based applications. Not only does Windows Forms provide many ready-to-use controls, it also provides the infrastructure for developing your own controls.


1 Answers

Here is a good article about this question. user controls

However in short

A Control is either inherited or completely custom. You write and handle many of the events yourself. You can even control how and when the control is drawn thru the use of GDI+ drawing.

A UserControl is a collection of controls placed together to be used in a certain way. For example you can place a GroupBox that contains Textbox’s, Checkboxes, etc. This is useful when you have to place the same group of controls on/in multiple forms or tabs. Note: you can write some custom events and drawing for UserControls also.

like image 101
Billy Avatar answered Sep 28 '22 16:09

Billy