Control Class

Defines the base class for controls, which are components with visual representation.

For a list of all members of this type, see Control Members.

            Derived classes

[Visual Basic]
Public Class Control
   Inherits Component
   Implements ISynchronizeInvoke, IWin32Window
public class Control : Component, ISynchronizeInvoke, IWin32Window
public __gc class Control : public Component, ISynchronizeInvoke,
public class Control extends Component implements
   ISynchronizeInvoke, IWin32Window

Thread Safety

Only the following members are safe for multithreaded operations: BeginInvoke, EndInvoke, Invoke, InvokeRequired, and CreateGraphics.


To create your own control class, inherit from the UserControl, Control classes, or from the other Windows Forms provided controls.

The Control class implements very basic functionality required by classes that display information to the user. It handles user input through the keyboard and pointing devices. It handles message routing and security. It defines the bounds of a control (its position and size), although it does not implement painting. It provides a window handle (hWnd).

Windows Forms controls use ambient properties so child controls can appear like their surrounding environment. An ambient property is a control property that, if not set, is retrieved from the parent control. If the control does not have a Parent and the property is not set, the control tries to determine the value of the ambient property through the Site property. If the control is not sited, if the site does not support ambient properties, or if the property is not set on the AmbientProperties object, the control uses its own default values. Typically, an ambient property represents a characteristic of a control, such as BackColor, that is communicated to a child control. For example, a Button will have the same BackColor as its parent Form by default. Ambient properties provided by the Control class include: Cursor, Font, BackColor, ForeColor, and RightToLeft.

Note   To make your Windows Forms application support Windows XP visual styles, be sure to set the FlatStyle property to FlatStyle.System and include a manifest with your executable. A manifest is an XML file that is included either as a resource within your application executable or as a separate file that resides in the same directory as the executable file. For an example of a manifest, see the Example section of the FlatStyle enumeration. For more information about using the visual styles available in Windows XP, see Using Windows XP Visual Styles in the Windows Development section of the MSDN Library.

Windows Forms has accessibility support built in, and provides information about your application that allows it to work with accessibility client applications such as screen enlarger and reviewer utilities, voice input utilities, on-screen keyboards, alternative input devices, and keyboard enhancement utilities. There are instances when you will want to provide additional information to accessibility client applications. There are two ways of providing this additional information. You can set the AccessibleName, AccessibleDescription, AccessibleDefaultActionDescription, and AccessibleRole property values, which will be reported to accessibility client applications. This method is typically used to provide limited accessibility information for existing controls. Alternatively, you can write your own class deriving from the AccessibleObject or Control.ControlAccessibleObject classes, providing as much accessibility information as needed.

Note   In order to maintain better performance, you should not set the size of a control in its constructor. The preferred method is to override the DefaultSize property.

The majority of the controls in the System.Windows.Forms namespace use the underlying Windows Common Control as a base to build upon. For more information about the Windows Common Controls, see the General Introduction to the Common Controls topic in the Windows Common Controls section of the Platform SDK documentation in the MSDN Library.


Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

Control Members | System.Windows.Forms Namespace | Form | ScrollableControl | ContainerControl | Component