Compartilhar via


Windows Forms Control Development Basics

A Windows Forms control is a class that derives directly or indirectly from System.Windows.Forms.Control. The following list describes common scenarios for developing Windows Forms controls:

  • Combining existing controls to author a composite control.

    Composite controls encapsulate a user interface that can be reused as a control. An example of a composite control is a control that consists of a text box and a reset button. Visual designers offer rich support for creating composite controls. To author a composite control, derive from System.Windows.Forms.UserControl. The base class UserControl 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.

  • Extending an existing control to customize it or to add to its functionality.

    A button whose color cannot be changed and a button that has an additional property that tracks how many times it has been clicked are examples of extended controls. You can customize any Windows Forms control by deriving from it and overriding or adding properties, methods, and events.

  • Authoring a control that does not combine or extend existing controls.

    In this scenario, derive your control from the base class Control. You can add as well as override properties, methods, and events of the base class. To get started, see How to: Develop a Simple Windows Forms Control.

The base class for Windows Forms controls, Control, provides the plumbing required for visual display in client-side Windows-based applications. Control provides a window handle, handles message routing, and provides mouse and keyboard events as well as many other user interface events. It provides advanced layout and has properties specific to visual display, such as ForeColor, BackColor, Height, Width, and many others. Additionally, it provides security, threading support, and interoperability with ActiveX controls. Because so much of the infrastructure is provided by the base class, it is relatively easy to develop your own Windows Forms controls.

See Also

Tasks

How to: Develop a Simple Windows Forms Control
How to: Create a Windows Forms Control That Shows Progress

Concepts

Developing a Composite Windows Forms Control
Varieties of Custom Controls