Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to add a Component Class vs User Control?

Tags:

I have a general idea, and there are some obvious cases, but there are also some gray areas for me - when is it best to use to extend from a component and when is it best to create a user control? This pertains to a specific work problem I am trying to solve, but the specifics of that are not important - a general answer to this question is enough for me.

like image 832
alexD Avatar asked Sep 21 '09 18:09

alexD


People also ask

What is the difference between a component and a control?

The difference between a control and a component is that a control has a user interface and a component does not.

What is the difference between custom controls 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 is the difference between user control and 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 user control and custom control in WPF?

A customControl can be styled and templated and best suited for a situation when you are building a Control Library. On the contrary, a UserControl gives you an easy way to define reusable chunk of XAML which can be reused widely in your application and when you don't need to use it as a Control Library .


1 Answers

In WPF and Windows Forms, both, the main difference is that a UserControl is meant to be a collection of controls - a reusable, single object "composed" from multiple controls themselves.

You'd impelemnt a Component/CustomControl/Control instead of a UserControl if you are making a single, primitive control with new behavior, instead of making a "control" that's composed of smaller controls. Component usually is a non-visual behavior, where a CustomControl/Control is usually for a visual control.

like image 79
Reed Copsey Avatar answered Oct 10 '22 19:10

Reed Copsey