Appendix A. Useful Control Properties, Methods, and Events

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.

PROPERTIES

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 fi t 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 with the same size. The GroupBox on the right contains two labels that cover its ClientRectangle and DisplayRectangle.

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.

The DisplayRectangle property gives the area in which you should normally place items within a control

Figure A.1. The DisplayRectangle property gives the area in which you should normally place items within a control

METHODS

The following table lists useful methods implemented by the Control class. All controls that inherit from this class inherit these properties unless they override the Control class's behavior.

METHOD

PURPOSE

Sub BringToFront()

Brings the control to the front of the stacking order.

Function Contains(ByVal child As Control) As Boolean

Returns True if the control child is contained by this control.

Function CreateGraphics() As Graphic

Creates a Graphic object that you can use to draw on the control's surface.

Function DoDragDrop(ByVal dragging_object As Object, ByVal allowed_effects As DragDropEffects)

Starts a drag-and-drop operation.

Sub DrawToBitmap(ByVal bm As Bitmap, ByVal rect As Rectangle)

Draws an image of the control including contained controls onto the Bitmap in the indicated Rectangle.

Function FindForm() As Form

Returns the Form that contains this control.

Function Focus() As Boolean

Gives the control the input focus.

Function GetChildAtPoint (ByVal pt As Point) As Control

Returns the control's child that contains the indicated point. If more than one control contains the point, the method returns the control that is higher in the stacking order.

Function GetNextControl (ByVal ctl As Control, ByVal next As Boolean) As Control

If next is True, returns the next control in the tab order of this control's children after control ctl. If next is False, returns the previous control in the tab order. Set ctl?=?Nothing to start from the start/end of the tab order. Returns Nothing when you reach the start/end.

Function GetPreferredSize (ByVal proposed_size) As Size

Returns a size that is big enough to hold the control's contents.

Function GetType() As Type

Returns a Type object representing the control's class. You can use this object to get information about the class.

Sub Hide()

Hides the control by setting its Visible property to False.

Sub Invalidate()

Invalidates some or all of the control and sends it a Paint event so that it redraws itself.

Sub Invoke(ByVal delegate As Delegate)

Invokes a delegate on the thread that owns the control.

Function PointToClient (ByVal screen_point Point) As Point

Converts a Point in screen coordinates into the control's coordinate system.

Function PointToScreen (ByVal control_point As Point) As Point

Converts a Point in control coordinates into the screen coordinate system.

Function RectangleToClient (ByVal screen_rect As Rectangle) As Rectangle

Converts a Rectangle in screen coordinates into the control's coordinate system.

Function RectangleToScreen (ByVal control_rect As Rectangle) As Rectangle

Converts a Rectangle in control coordinates into the screen coordinate system.

Sub Refresh()

Invalidates the control's client area, so the control redraws itself and its child controls.

Sub ResetBackColor()

Resets the control's background color to its default value.

Sub ResetCursor()

Resets the control's cursor to its default value.

Sub ResetFont()

Resets the control's font to its default value.

Sub ResetForeColor()

Resets the control's foreground color to its default value.

Sub ResetText()

Resets the control's text to its default value.

Sub Scale(ByVal scale_factor As Single)

Scales the control and any contained controls by multiplying the Left, Top, Width, and Height properties by scale_factor.

Sub Select()

Moves the input focus to the control. Some controls have overloaded versions.

Function SelectNextControl (ByVal ctl As Control, ByVal forward As Boolean, ByVal tab_stop_only As Boolean, ByVal include_nested As Boolean, ByVal wrap As Boolean) As Boolean

Moves the input focus to the next control contained within this one.

Sub SendToBack()

Sends the control to the back of the stacking order.

Sub SetBounds(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)

Sets the control's position and size.

Sub Show()

Displays the control by setting its Visible property to True.

Function ToString() As String

Returns a textual representation of the control. This is generally the type of the control followed by its most commonly used property.

Sub Update()

Makes the control redraw any invalidated areas.

EVENTS

The following table lists useful events implemented by the Control class. All controls that inherit from this class inherit these properties unless they override the Control class's behavior.

EVENT

PURPOSE

AutoSizeChanged

Occurs when the control's AutoSize property changes.

BackColorChanged

Occurs when the control's BackColor property changes.

BackgroundImageChanged

Occurs when the control's BackgroundImage property changes.

BackgroundImageLayoutChanged

Occurs when the control's BackgroundImageLayout property changes.

Click

Occurs when the user clicks the control. This event is at a higher logical level than the MouseClick event, and it can be triggered by other actions than a mouse click (such as pressing the Enter key or a shortcut key).

ContextMenuChanged

Occurs when the control's ContextMenu property changes.

ContextMenuStripChanged

Occurs when the control's ContextMenuStrip property changes.

ControlAdded

Occurs when a new control is added to the control's contained child controls

ControlRemoved

Occurs when a control is removed from the control's contained child controls.

CursorChanged

Occurs when the control's Cursor property changes.

DockChanged

Occurs when the control's Dock property changes.

DoubleClick

Occurs when the user double-clicks the control.

DragDrop

Occurs when the user drops something on the control in a drag-and-drop operation. This event handler should process the dropped information appropriately.

DragEnter

Occurs when the user drags something over the control in a drag-and-drop operation.

DragLeave

Occurs when the user drags something off of the control in a drag-and-drop operation.

DragOver

Occurs when the user has dragged something over the control in a drag-and-drop operation. This event fires repeatedly until the user drags off of the control, drops on the control, or cancels the drop.

EnabledChanged

Occurs when the control's Enabled property changes.

Enter

Occurs when the control is entered. This event fires before the GotFocus event.

FontChanged

Occurs when the control's Font property changes.

ForeColorChanged

Occurs when the control's ForeColor property changes.

GiveFeedback

Occurs during a drag-and-drop operation to let the drag source control take action.

GotFocus

Occurs when the control receives the input focus. This event fires after the Enter event. Generally, the Enter event is preferred.

HelpRequested

Occurs when the user requests help for the control. For example, if the user moves the focus to a TextBox and presses F1, the TextBox raises this event.

Invalidated

Occurs when part of the control is invalidated.

KeyDown

Occurs when the user presses a key while the control has the input focus.

KeyPress

Occurs when the user presses and releases a key while the control has the input focus.

KeyUp

Occurs when the user releases a key while the control has the input focus.

Layout

Occurs when the control should arrange its child controls. This event occurs before the Resize and SizeChanged events and is preferred for arranging child controls.

Leave

Occurs when the input focus leaves the control. This event fires before the LostFocus event.

LocationChanged

Occurs when the control's Location property changes. This event fires after the Move event fires.

LostFocus

Occurs when the input focus leaves the control. This event fires after the Leave event. Generally, the Leave event is preferred.

MarginChanged

Occurs when the control's Margin property changes.

MouseCaptureChanged

Occurs when the control loses a mouse capture.

MouseClick

Occurs when the user clicks the mouse on the control.

MouseDoubleClick

Occurs when the user double-clicks the mouse on the control.

MouseDown

Occurs when the user presses a mouse button down over the control.

MouseEnter

Occurs when the mouse enters the control.

MouseHover

Occurs when the mouse hovers over the control.

MouseLeave

Occurs when the mouse leaves the control.

MouseMove

Occurs when the mouse moves over the control.

MouseUp

Occurs when the user releases a mouse button over the control.

MouseWheel

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

Move

Occurs when the control is moved. This event fires before the LocationChanged event fires.

PaddingChanged

Occurs when the control's Padding property changes.

Paint

Occurs when the control must redraw itself. Normally the program draws on the control during this event (if it draws on the control at all).

ParentChanged

Occurs when the control's Parent property changes.

QueryContinueDrag

Occurs when something changes during a drag-and-drop operation so that the drag source can decide whether to modify or cancel the drag.

RegionChanged

Occurs when the control's Region property changes.

Resize

Occurs while the control is resizing. This event occurs after the Layout event, but before the SizeChanged event.

SizeChanged

Occurs while the control is resizing. This event occurs after the Layout and Move events.

SystemColorsChanged

Occurs when the system colors change. For instance, you might want to draw something using the same color that the operating system uses for active forms. If the user changes the system's color for borders, you can use this event to update your application.

TabIndexChanged

Occurs when the control's TabIndex property changes.

TabStopChanged

Occurs when the control's TabStop property changes.

TextChanged

Occurs when the control's Text property changes.

Validated

Occurs when the control has successfully finished validating its data.

Validating

Occurs when the control should validate its data.

VisibleChanged

Occurs when the control's Visible property changes.

EVENT SEQUENCES

Several situations generate a series of events in a precise order.

Mouse Events

When you click a control, the following events are raised in the order shown. The first instance of the MouseMove event can occur any number of times if you move the mouse while holding the mouse button down. The final MouseMove event occurs whether or not you move the mouse.

MouseDown

  [MouseMove]

Click

MouseClick

MouseUp

MouseCaptureChanged

MouseMove

When you double-click a control, the following events are raised in the order shown:

MouseDown

  [MouseMove]

Click

MouseClick

MouseUp

MouseCaptureChanged

MouseMove

MouseDown

DoubleClick

MouseDoubleClick

MouseUp

MouseCaptureChanged

MouseMove

Resize Events

When you resize a control, the following events are raised in this order. These events are repeated as long as you are resizing the control.

Layout

Resize

SizeChanged

Form controls also provide ResizeBegin and ResizeEnd events that occur before and after the other events, respectively.

Move Events

When you move a control, the following events are raised in this order. These events are repeated as long as you are moving the control.

Move

LocationChanged

Form controls also provide ResizeBegin and ResizeEnd events that occur before and after the other events, respectively.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.64.66