Setting Object Properties Using the Properties Window

   

When developing the interface of a project, you'll spend a lot of time viewing and setting object properties using the Properties window (see Figure 2.14). The Properties window contains four items:

  • An object drop-down list

  • A list of properties

  • A set of tool buttons used to change the appearance of the properties grid

  • A section showing a description of the selected property

Figure 2.14. Use the Properties window to view and change properties of forms and controls.

graphics/02fig14.jpg


Selecting an Object and Viewing Its Properties

The drop-down list at the top of the Properties window contains the name of the form with which you're currently working and all the controls (objects) on the form. To view the properties of a control, select it from the drop-down list or click the control on the form. You must have the pointer item selected in the toolbox to select an object by clicking it.

Viewing and Changing Properties

The first two buttons in the Properties window (Categorized and Alphabetic), enable you to select the format in which you view properties. When you select the Alphabetic button, the selected object's properties are listed in the Properties window in alphabetical order. When you click the Categorized button, all the selected object's properties are displayed by category. For example, the Appearance category contains properties such as BackColor and BorderStyle. When working with properties, select the view you're most comfortable with and feel free to switch back and forth between the views.

The Properties pane of the Properties window is used to view and set the properties of a selected object. You can set a property in one of the following ways:

  • Type in a value

  • Select a value from a drop-down list

  • Click a Build button for property-specific options

graphics/bookpencil.gif

Many properties can be changed by more than one of these methods .

To better understand how changing properties works, follow these steps:

  1. Start by creating a new Windows Application project. Name this project Changing Properties.

  2. Add a new text box to a form by double-clicking the TextBox tool in the toolbox. You're now going to change a few properties of the new text box.

  3. Select the Name property in the Properties window by clicking it, and then type in a name for the text boxcall it txtComments.

  4. Click the BorderStyle property and try to type in the word Big you can't; the BorderStyle property supports only selecting values from a list. You can type a value that exists in the list, however. When you selected the BorderStyle property, a drop-down arrow appeared in the value column. Click this arrow now to display a list of the values that the BorderStyle property accepts. Select FixedSingle and notice how the appearance of the text box changes. To make the text box appear three dimensional again, open the drop-down list and select Fixed3D.

  5. Select the BackColor property, type in some text, and press the Tab key to commit your entry. C# displays an Invalid Property Value error. This happened because, although you can type in text, you're restricted to entering specific values (in the case of BackColor, the value must be a number within a specific range or a named color). Click the drop-down arrow of the BackColor property and select a color from the drop-down list. (Selecting colors using the Color Palette is discussed later in this hour, and detailed information on using colors is provided in Hour 10, "Drawing and Printing.")

  6. Select the Font property. Notice that a Build button appears (a small button with three dots on it). When you click the Build button, a dialog box specific to the property you've selected appears. In this instance, a dialog box that allows you to manipulate the font of the text box appears (see Figure 2.15). Different properties display different dialog boxes when you click their Build buttons.

Figure 2.15. The Font dialog box gives you complete authority over the font of a control.

graphics/02fig15.jpg


By clicking a property in the Properties window, you can easily tell the type of input the property requires.

Working with Color Properties

Properties that deal with colors, such as BackColor and ForeColor, are unique in the way in which they accept values, yet all color- related properties behave the same way. In C#, all colors are expressed as a set of three numbers, each number having a value from 0 to 255. The set of numbers represents the Red, Green, and Blue (RGB) components of the color, respectively.

graphics/bookpencil.gif

The value 0,255,0, for instance, represents pure green, whereas the values 0,0,0 represent black and 255,255,255 represents white. (See Hour 10 for more information on the specifics of working with color.)

A color rectangle is displayed for each color property in the Properties window; this color is the selected color for the property. Text is displayed next to the colored rectangle. This text is either the name of a color or a set of RGB values that defines the color. Clicking in a color property causes a drop-down arrow to appear, but the drop-down you get by clicking the arrow isn't a typical drop-down list. Figure 2.16 shows what the drop-down list for a color property looks like.

Figure 2.16. The color drop-down list enables you to select from three sets of colors.

graphics/02fig16.jpg


The color drop-down list is composed of three tabs: Custom, Web, and System. Most color properties use a system color by default. Hour 10 goes into great detail on system colors, so I only want to mention here that system colors vary from computer to computer; they are the colors determined by the user when he or she right-clicks the desktop and chooses Properties from the desktop's shortcut menu. Use a system color when you want a color to be one of the user 's selected system colors. When a color property is set to a system color, the name of the color appears in the property sheet.

The Custom tab shown in Figure 2.17 is used to specify a specific color, regardless of the user's system color settings; changes to system colors have no effect on the property. The most common colors appear on the palette of the Custom tab, but you can specify any color you desire .

Figure 2.17. The Custom tab of the color drop-down list lets you specify any color imaginable.

graphics/02fig17.jpg


graphics/bookpencil.gif

The colors visible in the various palettes are limited by the number of colors that can be produced by your video card. If your video card doesn't support enough colors, some will appear dithered, which means they will appear as dots of colors rather than as a true, solid color.

The bottom two rows in the Custom color palette are used to mix your own colors. To assign a color to an empty color slot, right-click a slot in one of the two rows to access the Define Color dialog box (see Figure 2.18). Use the controls on the Define Color dialog box to create the color you desire, and then click Add Color. The new color appears on the color palette in the slot you selected, and it is automatically assigned to the current property.

Figure 2.18. The Define Color dialog box lets you create your own colors.

graphics/02fig18.jpg


The Web tab is used to pick colors from a list of named colors for building Web pages.

Viewing Property Descriptions

It's not always immediately apparent just exactly what a property is or does especially for new users of Visual Studio. The Description section at the bottom of the Properties window shows a simple description of the selected property (refer to Figure 2.14). To view a description, simply click a property or value area of a property.

You can hide or show the Description section of the Properties window at any time by right-clicking anywhere within the Properties window (other than in the value column or on the title bar) to display the Properties window shortcut menu and choosing Description. Each time you do this, you toggle the Description section between visible and hidden. To change the size of the Description box, click and drag the border between it and the Properties pane.


   
Top


Sams Teach Yourself C# in 24 Hours
Sams Teach Yourself Visual Basic 2010 in 24 Hours Complete Starter Kit (Sams Teach Yourself -- Hours)
ISBN: 0672331136
EAN: 2147483647
Year: 2002
Pages: 253
Authors: James Foxall

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