Windows Forms supports three kinds of user-defined controls: composite, extended, and custom. The following sections describe each kind of control and give recommendations for choosing the kind to use in your projects.
Composite Controls
A composite control is a collection of Windows Forms controls encapsulated in a common container. This kind of control is sometimes called a user control. The contained controls are called constituent controls.
A composite control holds all of the inherent functionality associated with each of the contained Windows Forms controls and enables you to selectively expose and bind their properties. A composite control also provides a great deal of default keyboard handling functionality with no extra development effort on your part.
For example, a composite control could be built to display customer address data from a database. This control could include a DataGridView control to display the database fields, a BindingSource to handle binding to a data source, and a BindingNavigator control to move through the records. You could selectively expose data binding properties, and you could package and reuse the entire control from application to application. For an example of this kind of composite control, see How to: Apply Attributes in Windows Forms Controls.
To author a composite control, derive from the UserControl class. The UserControl base class provides keyboard routing for child controls and enables child controls to work as a group. For more information, see Developing a Composite Windows Forms Control.
Extended Controls
You can derive an inherited control from any existing Windows Forms control. With this approach, you can retain all of the inherent functionality of a Windows Forms control, and then extend that functionality by adding custom properties, methods, or other features. With this option, you can override the base control's paint logic, and then extend its user interface by changing its appearance.
For example, you can create a control derived from the Button control that tracks how many times a user has clicked it.
In some controls, you can also add a custom appearance to the graphical user interface of your control by overriding the OnPaint method of the base class. For an extended button that tracks clicks, you can override the OnPaint method to call the base implementation of OnPaint, and then draw the click count in one corner of the Button control's client area.
Recommendation
Inherit from a Windows Forms control if:
Most of the functionality you need is already identical to an existing Windows Forms control.
You do not need a custom graphical user interface, or you want to design a new graphical user interface for an existing control.
Custom Controls
Another way to create a control is to create one substantially from the beginning by inheriting from Control. The Control class provides all of the basic functionality required by controls, including mouse and keyboard handling events, but no control-specific functionality or graphical interface.
Creating a control by inheriting from the Control class requires much more thought and effort than inheriting from UserControl or an existing Windows Forms control. Because a great deal of implementation is left for you, your control can have greater flexibility than a composite or extended control, and you can tailor your control to suit your exact needs.
To implement a custom control, you must write code for the OnPaint event of the control, as well as any feature-specific code you need. You can also override the WndProc method and handle windows messages directly. This is the most powerful way to create a control, but to use this technique effectively, you need to be familiar with the Microsoft Win32® API.
An example of a custom control is a clock control that duplicates the appearance and behavior of an analog clock. Custom painting is invoked to cause the hands of the clock to move in response to Tick events from an internal Timer component. For more information, see How to: Develop a Simple Windows Forms Control.
Recommendation
Inherit from the Control class if:
ActiveX Controls
Although the Windows Forms infrastructure has been optimized to host Windows Forms controls, you can still use ActiveX controls. There is support for this task in Visual Studio. For more information, see How to: Add ActiveX Controls to Windows Forms.
Windowless Controls
The Microsoft Visual Basic® 6.0and ActiveX technologies support windowless controls. Windowless controls are not supported in Windows Forms.