The Properties Window


The Properties Window

You use the Properties window to change the characteristics, or property settings, of the user interface elements on a form. A property setting is a quality of one of the objects in your program. You can change property settings by using the Properties window while you're creating your user interface, or you can add program code via the Code Editor to change one or more property settings while your program is running. For example, the trivia question that the Music Trivia program displays can be modified to appear in a different font or font size or with a different alignment. (With Visual Studio, you can display text in any font installed on your system, just as you can in Excel or Word.)

The Properties window contains an Object list that itemizes all the user interface elements (objects) on the form. The window also lists the property settings that can be changed for each object. You can click one of two convenient buttons to view properties alphabetically or by category. You'll practice changing the Font property of the first label in the Music Trivia program now.

Change a property

  1. Click the Label1 object on the form. (Label1 contains the text “What rock and roll instrument is often played with short, slapping thumb movements?”)

    To work with an object on a form, you must first select the object. When you select an object, resize handles surround it, and the property settings for the object are displayed in the Properties window.

  2. Click the Properties Window button on the Standard toolbar.

    The Properties window might or might not be visible in Visual Studio, depending on how it's been configured and used on your system. It usually appears below Solution Explorer on the right side of the development environment. (If it is visible, you don't need to click the button, but you should click the window to activate it.)

    You'll see a window similar to the following:

    graphic

    The Properties window lists all the property settings for the first label object (Label1) on the form. (In Visual Basic 2005, over 50 properties are associated with labels.) Property names are listed in the left column of the window, and the current setting for each property is listed in the right column. Because there are so many properties (including some that are rarely modified), Visual Studio organizes them into categories and displays them in outline view. If a category has a plus sign (+) next to it, you can click the collection title to display all the properties in that category. If a category has a minus sign (−) next to it, the properties are all visible, but you can hide the list under the category name by clicking the minus sign.

    TIP
    The Properties window has two handy buttons that you can use to further organize properties. Clicking the Alphabetical button lists all the properties in alphabetical order and puts them in just a few categories. Clicking the Categorized button organizes the property list into many logical categories. I recommend this view if you are new to Visual Studio.

  3. Scroll in the Properties window list box until the Font property is visible.

    The Properties window scrolls like a regular list box. If you are in categorized view, Font is in the Appearance category.

  4. Click the Font property name (in the left column).

    The current font (Microsoft Sans Serif) is partially displayed in the right column, and a button with three dots on it appears by the font name. This button is called an ellipsis button and indicates that a dialog box is available to customize the property setting.

  5. Click the Font ellipsis button in the Properties window.

    Visual Studio displays the Font dialog box, which you can use to specify new formatting characteristics for the text in the selected label on your form. The Font dialog box contains more than one formatting option; for each option you select, a different property setting will be modified.

    graphic

  6. Change the size of the font from 11 point to 12 point, and then change the font style from Regular to Italic. Click OK to confirm your changes.

    Visual Studio records your changes and adjusts the property settings accordingly. You can examine the changes by viewing your form in the Designer or by expanding the Font category in the Properties window.

    Now change a property setting for the Label2 object (the label that contains the text “The Bass Guitar”).

  7. In the Designer, click the second label object (Label2).

    When you select the object, resize handles surround it.

  8. Click the Font property in the Properties window.

    The Label2 object has its own unique set of property settings. Although the property names are the same as those of the Label1 object, the values in the property settings are distinct and allow the Label2 object to act independently on the form.

  9. Click the Font ellipsis button, set the font style to Bold, and then click OK.

  10. Scroll to the ForeColor property in the Properties window, and then click it in the left column.

  11. Click the ForeColor arrow in the right column, click the Custom tab, and then click a dark purple color.

    The text in the Label2 object is now bold and purple on the form.

    graphic

Congratulations! You've just learned how to set properties in a Visual Basic program by using the Visual Studio Properties window—one of the important skills in becoming a Visual Basic programmer.

Thinking About Properties

In Visual Basic, each user interface element in a program (including the form itself) has a set of definable properties. You can set properties at design time by using the Properties window. Properties can also be referenced in code to do meaningful work while the program runs. (User interface elements that receive input often use properties to convey information to the program.) At first, you might find properties a difficult concept to grasp. Viewing them in terms of something from everyday life can help.

Consider this bicycle analogy: a bicycle is an object you use to ride from one place to another. Because a bicycle is a physical object, it has several inherent characteristics. It has a brand name, a color, gears, brakes, and wheels, and it's built in a particular style. (It might be a touring bike, a mountain bike, or a bicycle built for two.) In Visual Basic terminology, these characteristics are properties of the bicycle object. Most of the bicycle's properties were defined when the bicycle was built. But others (tires, travel speed, and options such as reflectors and mirrors) are properties that change while the bicycle is used. The bike might even have intangible (that is, invisible) properties, such as age, current owner, or rental status. As you work with Visual Basic, you'll use object properties of both types—visible and invisible.



Microsoft Visual Basic 2005 Step by Step
Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))
ISBN: B003E7EV06
EAN: N/A
Year: 2003
Pages: 168

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