7.2.2

A control is a component that is visibly represented in a window and typically responds to user input in the form of keyboard events and mouse clicks. Being visible means that a control has a specified position and size. Examples include buttons, labels, check boxes, and list boxes. The Control class extends Component with more than 300 new properties, methods, and events. Some of the more commonly used members are shown in table 7.1.Table 7.1 Control members

Member

Description

Anchor

BackColor Click

DesignMode

Dispose() Dock

DoubleClick Enabled

Focus() Font

ForeColor GotFocus Height Hide()

KeyDown KeyPress KeyUp Left

Location

LostFocus MouseDown

MouseEnter

MouseHover

MouseLeave Show()

A public instance property which specifies which edges of the control, if any, are anchored to the edges of its container

A public instance property which specifies the background color of the control

A public instance event which is fired when the control is clicked

A protected instance property which indicates whether the control is currently in design mode

Disposes of the resources used by the control

A public instance property which specifies which edge of its container, if any, the control is docked to

A public instance event which is fired when the control is double-clicked

A public instance property which specifies whether the control is enabled or disabled

A public instance method which sets the input focus on the control

A public instance property which specifies the control's font

A public instance property which specifies the foreground color of the control

A public instance event which is fired when the control receives the input focus

A public instance property which specifies the height of the control in pixels

A public instance method which sets the Visible property of the control to false

A public instance event which is fired when a key is pressed while the control has the input focus

A public instance event which is fired when a key is pressed and released while the control has the input focus

A public instance event which is fired when a pressed key is released while the control has the input focus

A public instance property which specifies the x-coordinate of a control's left edge in pixels

A public instance property which specifies the top-left corner of the control relative to the top-left corner of its container

A public instance event which is fired when the control loses the input focus

A public instance event which is fired when the mouse button is clicked on the control

A public instance event which is fired when the mouse pointer enters the control

A public instance event which is fired when the mouse pointer hovers over the control

A public instance event which is fired when the mouse pointer leaves the control A public instance method which sets the Visible property of the control to true

continued on next pageTable 7.1 Control members (continued)

Member

Description

Size

A public instance property which specifies the width and height of the control

TabIndex

A public instance property which specifies the tab order of the control within its

 

container

TabStop

A public instance property which specifies whether the user can give the input

 

focus to the control using the TAB key

Text

A public instance property which specifies the text displayed on the control

Top

A public instance property which specifies the y-coordinate of a control's top edge

 

in pixels

WndProc()

A protected instance method which can be overridden to process native Windows

 

messages, (see example later in this chapter)

These are just a few of the many properties, methods, and events associated with controls, and inherited by forms. The good news is that you often need to use just a handful of these members to get the job done. For example, with a form, you may only need to set its Location and Size properties. For more complex controls, you may want to handle mouse activity, drag-drop events, keyboard entries, enabling, disabling, hiding, and showing the control, and so forth. The .NET SDK comes with extensive help documentation where you can find the full list of more than 300 properties, methods, and events associated with Windows Forms controls.