Name

Control

Synopsis

This is the fundamental base class for all the controls and forms in the framework.

After constructing a Control, you can add it to the Controls collection of a parent control and Show() it. (You can subsequently Hide() it again or change the Visible property.) You can also toggle whether it is Enabled.

Adding it to the Controls collection causes its Parent property to be set appropriately. HasChildren determines whether this control contains any children itself. Its index in the parent collection also determines its position in the z-order. You can use BringToFront() and SendToBack() for gross control of this feature.

TopLevelControl returns the top-level container—this is (usually) the outermost Form in which you will find the control. Note that if the control is contained in a TabPage that is not currently showing in the TabControl, the TopLevelControl property will return null.

You can set a ForeColor, BackColor, and Font with which to paint the control imagery (in particular, the Text). If you do not set these explicitly, it will inherit the AmbientProperties from its container. If all else fails, it will use the DefaultForeColor, DefaultBackColor, or DefaultFont. You can also specify a BackgroundImage that will be tiled across the control. Should the system theme or colors change, you can bind to the SystemColorsChanged event to update the controls appearance.

The general shape of the control can be specified with the Bounds property and SetBounds() method. ...

Get .NET Windows Forms in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.