Difference between Custom Controls, User controls and Components in C#: Both User control and custom control are direct or indirect derivations of Control class. Control, in turn, is derived from the component.See the derivation in below lines.
public class Component : MarshalByRefObject, IComponent, IDisposable
public class Control : Component, IDropTarget, ISynchronizeInvoke, IWin32Window,
IBindableComponent,IComponent, IDisposable
From this, it is easy to understand that the controls are much richer than components feature wise.
Components don’t have GUI like user controls or custom controls.Components are more of APIs.Examples of .NET components are Timer controls, File Browser, Data Source controls etc. A component can’t contain controls inside it.
In detail the derivation hierarchy of UserControl, Custom Control and Component is shown below
//UserControl public partial class UserControl1 : UserControl //UserControl1 is your control which is derived from UserControl public class UserControl : ContainerControl public class ContainerControl : ScrollableControl, IContainerControl public class ScrollableControl : Control, IComponent, IDisposable public class Control : Component, IDropTarget, ISynchronizeInvoke, IWin32Window, IBindableComponent, IComponent, IDisposable
//CustomControl public partial class SpecialButton : Button //SpecialButton is your custom control which is derived from Button public class Button : ButtonBase, IButtonControl public abstract class ButtonBase : Control public class Control : Component, IDropTarget, ISynchronizeInvoke, IWin32Window, IBindableComponent, IComponent, IDisposable
//Component public partial class YourComponent : Component //YourComponent is your derived from Component public class Component : MarshalByRefObject, IComponent, IDisposable
Leave a Reply