Learn the differences between the various types of custom controls, and find out how to integrate your controls into Visual Studio and make them easy to use.

WEBINAR:

On-Demand

ccording to MSDN's documentation (specifically Varieties of Custom Controls) there are three types of custom controls. The names Microsoft has chosen to use for these three in the documentation are confusing: composite control, extended control, and custom control. The inclusion of "custom control" as a type means you can never be sure which type is being referred to by the generic term "custom control." The following discussion substitutes "raw control" for the third type of custom control.
Furthermore, this list of three custom controls should really be a list of four custom controls: composite control, extended user control, extended system control, and raw control, because although there's no conceptual difference between extending a user control and extending a system control, there is a practical difference, as you will see shortly.

What You Need

Visual Studio 2008 or VS2005

C# 3.0 or 2.0 (there are a couple of spots you'll need to adjust if using C# 2.0 in VS2005)

.NET Framework: 2.0 or higher

Figure 1. Control Class Hierarchy: The figure indicates the three types of controls defined by MSDN documentation: an extended user control derives from one of your own controls, a composite control derives from UserControl, and a raw control derives from Control.

Figure 1 shows a class diagram of the AlarmClockControl, which was discussed extensively in an earlier related article called .NET Building Blocks: Custom User Control Fundamentals. The diagram shows its inheritance from ClockControl, through several intermediaries, to the ultimate parent class of all controls, the generically named Control. The figure indicates three of the four types of controls so you can match the concepts to the implementation. The following sections provide details for each of the four types of custom controls, showing how to create each type, what Visual Studio provides to get you started, and what rendering you see in the visual designer.
Obviously not all controls have equivalent capabilities. The earlier article showed how the Visual Studio's UserControl Test Container lets you execute disembodied controls (without embedding them in a form). One subtle question that can now be addressed is: which controls may be loadable in the UserControl Test Container? According to MSDN documentation (How to: Test the Run-Time Behavior of a UserControl), the only requirement is that your user control must have at least one public constructor. The catch, however, is what they mean by "user control." Notice that the list of three types of custom controls from MSDN does not include "user control." In this context, user control really means a control that derives directly or indirectly from UserControl, in other words: composite controls or extended user controls only. Extended system controls or raw controls do not qualify. That's why the test container is called the UserControl Test Container.

Advertiser Disclosure:
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.

Thanks for your registration, follow us on our social networks to keep up-to-date