System.Windows.Forms.UserControl Class

Provides an empty control that can be used to create other controls.

See Also: UserControl Members

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.ComponentModel.Designer("System.Windows.Forms.Design.UserControlDocumentDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.ComponentModel.Design.IRootDesigner))]
[System.ComponentModel.Designer("System.Windows.Forms.Design.ControlDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
[System.ComponentModel.DesignerCategory("UserControl")]
[System.ComponentModel.DefaultEvent("Load")]
public class UserControl : ContainerControl

Remarks

By extending System.Windows.Forms.ContainerControl, System.Windows.Forms.UserControl inherits all the standard positioning and mnemonic-handling code that is necessary in a user control.

The System.Windows.Forms.UserControl gives you the ability to create controls that can be used in multiple places within an application or organization. You can include all the code needed for validation of common data you ask the user to input; some examples of this are e-mail addresses (see Example section), telephone numbers, and postal codes. Another efficient use of the user control is to simply preload a System.Windows.Forms.ComboBox or System.Windows.Forms.ListBox with static items you commonly use in almost every application; some examples of this are countries/regions, cities, states, and office locations. For more information about authoring custom controls, see Developing Windows Forms Controls with the .NET Framework.

Note:

You might consider creating a namespace that contains several classes of user controls and compiling it into one DLL. This DLL can be referenced and distributed with the application or all applications within an organization. This gives you the ability to reference the user control in many applications and save time laying out and coding the contained elements of the user control. A user control also gives you consistency within or across applications; for example, all address information input blocks will all have the same appearance and behavior. Consistency gives your application a more polished and professional appearance.

You can host Windows Forms System.Windows.Forms.UserControl derived classes inside of a form, on another System.Windows.Forms.UserControl, inside of Internet Explorer on a Web page, or inside a System.Windows.Forms.WebBrowser control hosted on a form.

Note:

When hosting a System.Windows.Forms.UserControl inside of the System.Windows.Forms.WebBrowser control, you cannot turn off Visual Styles using the META tag value MSThemeCompatible. For more information about Visual Styles, see Rendering Controls with Visual Styles.

Note that for Smartphone applications, this control requires Windows Mobile Version 5.0 software for Smartphones.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0