This documentation is archived and is not being maintained.

Inheriting from the UserControl Class

If you want to combine the functionality of one or more Windows Forms controls with custom code, then you should create a user control. User controls combine rapid control development with standard Windows Forms control functionality and the versatility created by adding custom properties and methods. When creating a user control, you are presented with a visible designer, upon which you may place standard Windows Forms controls. These controls retain all of their inherent functionality, as well as the look and feel of standard controls, but once they are built into the user control they are no longer available to the developer through code. The user control does its own painting and also handles all of the basic functionality associated with controls.

To create a user control

  1. Create a new Windows Control Library project.

    A new project is created with a blank user control.

    Note   The Windows Control Library template is not available in the Standard Edition of Visual Basic and Visual C# .NET. For more information, see Visual Basic Standard Edition Features or Visual C# Standard Edition Features.
  2. Drag controls from the Windows Forms tab of the Toolbox onto your designer.
  3. These controls should be positioned and designed as you want them to appear in the final user control. If you want to allow developers to access the constituent controls, you must declare them as public, or selectively expose properties of the constituent control. For details, see Exposing Properties of Constituent Controls.
  4. Implement any custom methods or properties that your control will incorporate. For details, see Properties, Methods, and Events for Custom Controls.
  5. Save and test your control.

See Also

Inheriting from the Control Class | Inheriting from Existing Windows Forms Controls | Authoring Controls for Windows Forms | Troubleshooting Inherited Event Handlers in Visual Basic .NET