Introduction to Controls

function OpenWin(url, w, h) { if(!w) w = 400; if(!h) h = 300; window.open(url, "_new", "width=" + w + ",height=" + h + ",menubar=no,toobar=no,scrollbars=yes", true); } function Print() { window.focus(); if(window.print) { window.print(); window.setTimeout('window.close();',5000); } }
Team-Fly    

Special Edition Using Microsoft® Visual Basic® .NET
By Brian Siler, Jeff Spotts
Table of Contents
Chapter 11.  Fundamental Controls


As you have learned,a control is an object that interacts with the user or the program. The Visual Basic .NET help system's definition of controls states that "components that provide visible parts of the user interface are called controls." Technically, however, a control does not have to be visible in the user interface. The Timer control, for example, is never visible to the user.

You have also learned how to set some of the properties that govern a control's appearance and behavior. Table 11.1 describes common properties that apply to virtually all controls.

Table 11.1. Properties Common to Controls

Property

Description

Name

The name utilized by program code when referring to the control. Visual Basic assigns default names that end with sequential numbers (TextBox1, TextBox2, and so on); however, it is good practice to change the names of controls that will need to be referenced in code at some point.

Size

An ordered pair of numbers that specifies the width and height, respectively, of the control (in pixels). For example, a control whose Size property is set to 64, 24 would be drawn to be 64 pixels wide and 24 pixels high. A control's size may also be expressed as individual Width and Height properties in lieu of the ordered pair. Clicking the plus sign to the left of the Size property in the Properties window reveals the Width and Height properties. The Size property, as well as the Width and Height properties, can be modified at design time by dragging a selected control's sizing handles or by typing new values into the Properties window. The Width and Height properties can also be changed for most controls at runtime with code like cmdTest.Height = 300.

Location

An ordered pair of numbers that specifies the horizontal and vertical position of the upper-left corner of the control (in pixels) respective to the left and top edges of its container. For example, a control (drawn on a form) whose Location property is set to 120, 270 would be drawn so that its upper-left corner is 120 pixels from the left edge of the form and 270 pixels from the top edge of the form. A control's location may also be expressed as individual X and Y properties in lieu of the ordered pair, where X represents the distance from the left edge and Y represents the distance from the top edge of the control's container. Clicking the plus sign to the left of the Location property in the Properties window reveals the X and Y properties. The Location property, as well as the X and Y properties, can be modified at design time by dragging a control to a new location on the form or by typing new values into the Properties window. The X and Y properties can also be changed for most controls at runtime with code like cmdTest. X = 50.

Enabled

Set to True or False to specify whether the control is enabled; that is, whether the user may interact with the control. For example, a Button control whose Enabled property is set to False, while visible to the user, cannot be clicked. Typically a control whose Enabled property is set to False has a "grayed-out" appearance.

Visible

Set to True or False to specify whether the control can be seen by the user at runtime.

Locked

A control whose Locked property is set to True cannot be moved or resized at design time. Typically, once you have arranged the controls on a form the way you want them, you will set the Locked property of each control to True to avoid accidentally moving or resizing it. You can set the Locked property of all of a form's controls at one time by right-clicking the form, and then selecting Lock Controls from the pop-up menu.

BackColor

The background color of the control, specified by clicking the drop-down arrow in the Properties window and selecting the desired color.

ForeColor

The color used to display text on the control, specified by clicking the drop-down arrow in the Properties window and selecting the desired color.

TabStop

The TabStop property determines whether the user can move the focus to the control by pressing the Tab key. A control whose TabStop property is set to False is bypassed as the user tabs from control to control.

TabIndex

If the control's TabStop property is set to True, the TabIndex property determines the order in which controls receive the focus. Each control on a form has a unique TabIndex property; by default, the TabIndex property is assigned in ascending order as controls are added to the form at design time. The first control placed on a form receives a TabIndex property of 0, the second control receives 1, and so forth. You can change the order in which the controls on a form are "tabbed to" by manually modifying the TabIndex properties of the controls. Alternately, Visual Basic .NET has a nice tool that lets you click the controls on a form in the order in which you want them to be accessed. You can use this tool by clicking View, Tab Order in Visual Basic .NET's Main menu while the desired form is displayed in Design mode.

Font

For controls that display text (including caption-like text, like on a Button control), the Font property determines the font used to render that text. Clicking the ellipsis in the Properties window presents you with a dialog box in which you can select a font. The Font property has individual subproperties (Name, Size, Unit, Bold, Italic, Strikeout, and Underline) that can be accessed by clicking the plus sign to the left of the Font property in the Properties window. To set these subproperties in code, use a statement like txtName.Font.Bold = True.

Cursor

Determines which pointer appears when the user passes the mouse over the control. Clicking the drop-down arrow in the Properties window presents a number of possible mouse pointers. For example, you may want the mouse pointer to change to a hand when the control is passed over, indicating that the control may be clicked.


    Team-Fly    
    Top
     



    Special Edition Using Visual Basic. NET
    Special Edition Using Visual Basic.NET
    ISBN: 078972572X
    EAN: 2147483647
    Year: 2001
    Pages: 198

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net