JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

The Control Class

The Control class is in the System.Windows.Forms namespace. It serves as a base class for the Windows controls we'll see—such as rich text boxes—which have this class hierarchy (that is, the MarshalByRefObject class is derived from the Object class, and the Component class is derived from the MarshalByRef Object class, and so on):

Object
   MarshalByRefObject
      Component
         Control
            TextBoxBase
               RichTextBox

Because Windows controls are based on the Control class, they inherit many properties, methods, and events from that class, so I'll list the more interesting ones here. (Keep in mind that the Form class is also derived from Control, so it also shares these properties, methods, and events). You can find noteworthy public properties of the Control class in Table 5.1, noteworthy methods in Table 5.2, and events in Table 5.3.

Table 5.1: Noteworthy public properties of Control objects.

Property

Means

AllowDrop

Sets/gets a value specifying if the control can accept data dropped into it.

Anchor

Sets/gets which edges of the control are anchored.

BackColor

Sets/gets the background color of this control.

BackgroundImage

Sets/gets the background image in the control.

Bottom

Gets the distance between the bottom of the control and the top of its container's client area.

Bounds

Sets/gets the control's bounding rectangle.

CanFocus

Returns a value specifying if the control can receive the focus.

CanSelect

Returns a value specifying if the control can be selected.

Capture

Sets/gets a value specifying if the control has captured the mouse.

CausesValidation

Sets/gets a value specifying if the control causes validation for all controls that require validation.

ContainsFocus

Returns a value specifying if the control has the input focus.

ContextMenu

Sets/gets the shortcut menu associated with this control.

Controls

Sets/gets the collection of controls contained within the control.

Cursor

Sets/gets the cursor displayed when the user moves the mouse pointer over this control.

DataBindings

Gets the data bindings for the control.

Dock

Sets/gets which edge of the parent a control is docked to.

Enabled

Sets/gets a value specifying if the control is enabled.

Focused

Returns a value specifying if the control has input focus.

Font

Sets/gets the current font for the control.

ForeColor

Sets/gets the foreground color of the control.

HasChildren

Returns a value specifying if the control contains child controls.

Height

Sets/gets the height of the control.

Left

Sets/gets the x-coordinate of a control's left edge in pixels.

Location

Sets/gets the coordinates of the upper-left corner of the control with respect to the upper-left corner of its container.

Name

Sets/gets the control's name.

Parent

Sets/gets the control's parent container.

Right

Returns the distance between the right edge of the control and the left edge of its container.

RightToLeft

Sets/gets a value indicating if the alignment of the control's elements is reversed to support right-to-left fonts.

Size

Sets/gets the height and width of the control.

TabIndex

Sets/gets the tab order of this control in its container.

TabStop

Sets/gets a value specifying if the user can tab to this control with the Tab key.

Tag

Sets/gets an object that contains data about the control.

Text

Sets/gets the text connected to this control.

Top

Sets/gets the top coordinate of the control.

Visible

Sets/gets a value specifying if the control is visible.

Width

Sets/gets the width of the control.

Table 5.2: Noteworthy public methods of Control objects.

Method

Means

BringToFront

Brings the control to the front of the stacking order.

Contains

Retrieves a value specifying if the control is a child of this control.

CreateGraphics

Creates a Graphics object for the control.

Dispose

Releases the resources used by the control.

DoDragDrop

Starts a drag-and-drop operation.

Equals

Indicates if two controls are equal.

FindForm

Retrieves the form that this control is on.

Focus

Gives the focus to the control.

GetChildAtPoint

Gets the child control at the specified coordinates.

GetNextControl

Retrieves the next control in the tab order of child controls.

GetType

Gets the type of the control.

Hide

Hides the control.

Invalidate

Invalidates a part of the control and sends a paint message to the control.

PointToClient

Translates the location of the specified screen point to client coordinates.

PointToScreen

Translates the location of the specified client point to screen coordinates.

RectangleToClient

Translates the location of the specified screen rectangle to client coordinates.

RectangleToScreen

Translates the location of the specified client rectangle to screen coordinates.

Refresh

Forces the control to invalidate its client area and repaint itself (and any child controls).

Scale

Scales the control and any child controls.

Select

Activates this control.

SendToBack

Sends the control to the back of the stacking order.

SetBounds

Sets the bounds of the control.

Show

Displays the control (sets its visible property to True).

ToString

Returns a string that represents the current control.

Update

Forces the control to paint any currently invalid areas.

Table 5.3: Noteworthy public events of Control objects.

Event

Means

BackColorChanged

Occurs when the value of the BackColor property is changed.

BackgroundImageChanged

Occurs when the BackgroundImage property is changed.

Click

Occurs when the control is clicked.

ContextMenuChanged

Occurs when the ContextMenu property value is changed.

ControlAdded

Occurs when a new control is added.

ControlRemoved

Occurs when a control is removed.

CursorChanged

Occurs when the Cursor property value is changed.

Disposed

Represents the method which will handle the Disposed event of a Component.

DoubleClick

Occurs when the control is double-clicked.

DragDrop

Occurs when a drag-and-drop operation is completed.

DragEnter

Occurs when an object is dragged into the control's bounds.

DragLeave

Occurs when an object has been dragged into and out of the control's bounds.

DragOver

Occurs when an object has been dragged over the control's bounds.

EnabledChanged

Occurs when the Enabled property value is changed.

Enter

Occurs when the control is entered.

FontChanged

Occurs when the Font property value is changed.

ForeColorChanged

Occurs when the ForeColor property value is changed.

GotFocus

Occurs when the control receives focus.

Invalidated

Occurs when a control's display is updated.

KeyDown

Occurs when a key is pressed down while the control has focus.

KeyPress

Occurs when a key is pressed while the control has focus.

KeyUp

Occurs when a key is released while the control has focus.

Layout

Occurs when a control has to lay out its child controls.

Leave

Occurs when the control is left.

LocationChanged

Occurs when the Location property value is changed.

LostFocus

Occurs when the control loses focus.

MouseDown

Occurs when the mouse pointer is over the control and a mouse button is pressed.

MouseEnter

Occurs when the mouse pointer enters the control.

MouseHover

Occurs when the mouse pointer hovers over the control.

MouseLeave

Occurs when the mouse pointer leaves the control.

MouseMove

Occurs when the mouse pointer is moved over the control.

MouseUp

Occurs when the mouse pointer is over the control and a mouse button is released.

MouseWheel

Occurs when the mouse wheel moves while the control has focus.

Move

Occurs when the control is moved.

Paint

Occurs when the control is redrawn.

ParentChanged

Occurs when the Parent property value is changed.

Resize

Occurs when the control is resized.

RightToLeftChanged

Occurs when the Right-ToLeft property value is changed.

Validated

Occurs when the control is done validating.

Validating

Occurs when the control is validating.

VisibleChanged

Occurs when the Visible property value is changed.

I've included Tables 5.1, 5.2, and 5.3 for reference sake, and it's really worth looking through these tables, finding out, for example, what properties to use to change the background color of a control (BackColor), what method makes a control invisible (Hide), what event handles mouse button press events (MouseDown), and so on. Note that when listing the noteworthy properties, methods, and events of Windows controls in similar tables in this and the next chapters, I'm going to omit those inherited from the Control class, because there simply isn't room to list them all. You'll find all those common Control properties, methods, and events in Tables 5.1, 5.2, and 5.3.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor