A control interacts with a program or the user through properties, methods, and events. Although each type of control provides different features, they are all derived from the Control class. This class provides many useful properties, methods, and events that other controls inherit, if they don’t take special action to override them. The following sections describe some of the most useful of these inherited features.
The following table lists properties implemented by the Control class. All controls that inherit from this class inherit these properties unless they override the Control class’s behavior.
Property | Purpose |
---|---|
AllowDrop | Determines whether the control allows drag-and-drop operations. |
Anchor | Determines which of the control’s edges are anchored to the edges of the control’s container. |
AutoSize | Determines whether the control automatically resizes to fit its contents. |
BackColor | Determines the control’s background color. |
BackgroundImage | Determines the control’s background image. |
BackgroundImageLayout | Determines how the control’s background image is used to fill the control. This can be Center, None, Tile, Stretch, and Zoom. |
Bottom | Returns the distance between the top edge of the control’s container and the bottom edge of the control. This is read-only. Modify the Top and Height properties to change this value. |
Bounds | Determines the control’s size and location, including nonclient areas. |
CanFocus | Determines whether the control can receive the input focus. See also the Focus method. |
CanSelect | Determines whether the control can select. For example, a TextBox can select some or all of its text. See also the Select method. |
Capture | Determines whether the control has captured the mouse. |
CausesValidation | Determines whether the control makes other controls validate when it receives the focus. |
ClientRectangle | This Rectangle structure represents the control’s client area. |
ClientSize | This Size structure represents the control’s height and width. |
ContainsFocus | Indicates whether the control or one of its child controls has the input focus. This is read-only. |
ContextMenu | Determines the context menu associated with the control. |
ContextMenuStrip | Determines the context menu strip associated with the control. |
Controls | This collection contains references to the controls contained within this control. |
Cursor | Determines the cursor that the control displays when the mouse is over it. |
DataBindings | Gets the control’s DataBindings, used to bind the control to a data source. |
DefaultBackColor | Returns the control’s default background color. |
DefaultFont | Returns the control’s default font. |
DefaultForeColor | Returns the control’s default foreground color. |
DisplayRectangle | Returns a Rectangle structure giving the control’s display area. Figure A-1 shows two GroupBoxes containing two Labels each. The Labels in the left GroupBox show the ClientRectangle (Label1) and DisplayRectangle (Label2) of the GroupBox. |
Dock | Determines the edge of the control’s parent to which the control is docked. |
Enabled | Determines whether the control will interact with the user. |
Focused | Indicates whether the control has the input focus. This is read-only. |
Font | Determines the control’s font. |
ForeColor | Determines the control’s foreground color. |
Handle | Returns the control’s window handle. This is read-only. |
HasChildren | Indicates whether the control holds any child controls. This is read-only. Also see the Controls property. |
Height | Determines the control’s height. |
InvokeRequired | Returns True if the calling code is running on a thread different from the control’s thread and therefore must use an invoke method to interact with the control. |
Left | Determines the X coordinate of the control’s left edge. |
Location | This Point structure determines the position of the control’s upper-left corner. |
Margin | Determines the spacing between this control and another control’s margin within an arranging container. |
MaximumSize | Determines the control’s largest allowed size. |
MinimumSize | Determines the control’s smallest allowed size. |
ModifierKeys | Indicates what modifier keys (Shift, Ctrl, and Alt) are pressed. This is read-only. |
MouseButtons | Indicates what mouse buttons (Left, Right, Middle, None) are pressed. This is read-only. |
MousePosition | Returns a Point structure giving the mouse’s current position in screen coordinates (the point (0, 0) is in the screen’s upper-left corner). This is read-only. |
Name | Determines the control’s name. |
Padding | Determines the spacing of the control’s contents. |
Parent | Determines the parent containing the control. |
PreferredSize | Returns a size that is big enough to hold the control’s contents. |
Region | Determines the control’s window region. This is the area in which the control may draw. |
Right | Returns the distance between the left edge of the control’s container and the right edge of the control. This is read-only. Modify the Left and Width properties to change this value. |
Size | This Size structure determines the control’s size including client and nonclient areas. |
TabIndex | Determines the control’s position in its container’s tab order. If more than one control has the same TabIndex, they are traversed front to back using the stacking order. |
TabStop | Determines whether the user can tab to the control. |
Tag | This property can hold an object that you want to associate with the control. |
Text | Determines the control’s text. |
Top | Determines the Y coordinate of the control’s top edge. |
TopLevelControl | Returns the control’s top-level ancestor. Usually that is the outermost Form containing the control. This is read-only. |
Visible | Determines whether the control is visible. |
Width | Determines the control’s width. |
Figure A-1: The DisplayRectangle property gives the area in which you should normally place items within a control.