Home

Microsoft Visual Studio Tools: The Properties Window

     

Introduction

A property is a piece of information that characterizes or describes a control. It could be related to its location or size. It could be its color, its identification, or any visual aspect that gives it meaning. The properties of an object can be changed either at design time or at run time. You can also manipulate these characteristics both at design and at run times. This means that you can set some properties at design time and some others at run time.

 

To manipulate the properties of a control at design time, first select it on the form. While a control is selected, use the Properties window to manipulate the properties of the control at design time. To access the Properties window if it is not visible:

  • On the main menu, you can click View -> Properties Window
  • On the form, you can right-click anything (either the form itself or any control positioned on it) and click Properties
  • The shortcut to display the Properties window is F4
 

Description

The Properties window uses the behaviors we reviewed in Lesson 1 about auto-hiding, docking, floating or tabbing the tools that accompany Microsoft Visual Studio 2010. This means that you can position it on one side of the screen or to have it float on the screen as you wish.

The Properties window is divided in 5 sections:

Sections of the Properties window

The Properties window starts on top with a title bar, which displays the string Properties. If the window is docked somewhere, it displays the Window Position Window Position, the Auto-Hide Auto-Hide, and the Close Close buttons on its right side. If the window is floating, it would display only the Close button.

Under the title bar, the Properties window displays a combo box. The content of the combo box is the name of the form plus the names of the controls currently on the form. Besides the technique we reviewed earlier to select a control, you can click the arrow of the combo box and select a control from the list:

Combo Box

Under the combo box, the Properties window displays a toolbar with 4 buttons.

Under the toolbar, the Properties window displays the list of properties of the selected control(s). On the right side, the list is equipped with a vertical scroll bar. The items in the Properties window display in a list set when installing Microsoft Visual Studio. In the beginning, you may be regularly lost when looking for a particular property because the list is not arranged in a strict order of rules. You can rearrange the list. For example, you can cause the items to display in alphabetic order. To do this, on the toolbar of the Properties window, click the Alphabetic button . To restore the list, you can click the categorized button Categorized.

Two lists share the main area of the Properties window. When the list of properties is displaying, the Properties button is clicked Properties. The second is the list of events. Therefore, to show the events, you can click the Events button . If the events section is displaying, to show the list of properties, you can click the Properties button Properties.

Under the list of properties, there is a long bar that displays some messages. The area is actually a help section that displays a short description of the property that is selected in the main area of the Properties window.

Accessing the Properties of One or More Controls

Based on a previous description,

  • If the Properties window is already displaying, to access the properties of the form or of a control, simply click it
  • If the Properties window is not displaying, to access the characteristics of an object, right-click either the form or a control on the form and click Properties
  • If the Properties window is not available, to access the characteristics, click either the form or a control on the form and, on the main menu, click View -> Properties

When a control is selected, the Properties window displays only its characteristics:

Properties

You can also change some characteristics of various controls at the same time. To do this, first select the controls on the form and access the Properties window:

Common properties of different controls

When various controls have been selected:

  • The Properties window displays only the characteristics that are common to the selected controls
  • The combo box on top of the Properties window is empty
  • Some fields of the Properties window appear empty because the various controls that are selected have different values for those properties

ApplicationApplication: Introducing the Properties Window

  1. To create a new application, on the main menu, click File -> New Project...
  2. In the middle list, click Windows Forms Application
  3. Set the Name to Exercise4 and click OK

Properties Categories

 

Introduction

Each field in the Properties window has two sections: the property’s name and the property's value:
 

Properties

The name of a property is represented on the left column. This is the official name of the property. The names of properties are in one word. You can use this same name to access the property in code.

 The box on the right side of each property name represents the value of the property that you can set for an object. There are various kinds of fields you will use to set the properties. To know what particular kind a field is, you can click its name. To set or change a property, you use the box on the right side of the property’s name: the property's value, also referred to as the field's value.

ApplicationApplication: Displaying the Properties Window

  • To display the Properties windows, on the main menu, click View -> Properties Window

Empty Fields

Property Empty  

By default, these fields have nothing in their value section. Most of these properties are dependent on other settings of your program. For example, you can set a menu property for a form only after you have created a menu.

To set the property on such a field, you can type in it or select from a list. 

 

ApplicationApplication: Checking Empty Fields

  • Click the body of the form.
    In the Properties windows, notice that the AccessibleName and the Tag fields are empty

Text Fields

There are fields that expect you to type a value. Most of these fields have a default value. Here is an example:

Property Text

To change the value of the property, click the name of the property, type the desired value, and press Enter.

While some properties, such as the Text, would allow anything, some other fields expect a specific type of text, such as a numeric value.

ApplicationApplication: Checking Text Fields

  1. In the Properties windows, click Text and notice that it contains a string in bold characters
  2. Click (Name) and notice that it contains some bold characters

Numeric Fields

Some fields expect a numeric value. In this case, you can click the name of the field and type the desired value. Here is an example:

Numeric Property

. If you type an invalid value, you would receive a message box notifying you of the error:

Error

When this happens, click OK and type a valid value. If the value is supposed to be an integer, make sure you don't type it as a decimal number.

ApplicationApplication: Checking Numeric Fields

  1. In the Common Controls section of the Toolbox, click NumericUpDown NumericUpDown and click the form (no need for precision)
  2. While the control is still selected on the form, in the Properties windows, click Value and notice that it contains a number string in bold characters
  3. Click the DecimalPlaces, the Increment, the Maximum, and the Minimum fields to see that they contain numeric values:
     

Date-Based Fields

Some fields expect you to enter a date. You must type a valid date recognized by the operating system and the Regional and Language Settings in Control Panel. If you enter an invalid date, you would receive an error.

ApplicationApplication: Checking Date and Time Fields

  1. In the Common Controls section of the Toolbox, click DateTimePicker and click the form (no need for precision)
  2. While the control is still selected on the form, in the Properties windows, click Value and notice that it contains a date and time value
  3. Click the MinDate and the MaxDate fields to see their values:
     
    Date-Based Field

Expandable Fields

 
Expandable Property

Some fields have a right-point button. This indicates that the property has a set of sub-properties that actually belong to the same property and are defined together. To expand such a field:

  • Click its right-point button
  • Double-click the property name

After expanding the field, it would be equipped with a down-right pointing arrow:

Properties

To collapse the field, click the - button.

Some of the properties are numeric based, such as the Location or the Size. With such a property, you can click its name and type two numeric values separated by a comma. Some other properties are created from an enumeration or a class. If you expand such a field, it would display various options. Here is an example from the Font property:

Properties

With such a property, you should select from a list.

ApplicationApplication: Checking Expandable Fields

  1. Click an empty area of the form to select the form
  2. In the Properties window, double-click the Font name to expand it and notice that it display some previously hidden items

Boolean Fields

 
Boolean Fields

Some fields can have only a True or False value. To change their setting, you can either select from the combo box or double-click the property to toggle to the other value.

 

ApplicationApplication: Checking Boolean Fields

  1. In the Properties window click Enabled and notice that it displays True
  2. Under Font, click Bold and notice that it displays False 

Action Fields

Some fields would require a value or item that needs to be set through an intermediary action. Such fields display an ellipsis button Ellipsis. When you click the button, a dialog box would come up and you can set the value for the field.

Property Action
 

ApplicationApplication: Checking Action Fields

  1. In the Common Controls section of the Toolbox, click PictureBox and click the form (no need for precision)
  2. While the control is still selected on the form, in the Properties windows, click Image and notice that the field displays an ellipsis button Ellipsis Button
     
    Picture Box
  3. Click the ellipsis button and notice that a dialog box comes up
  4. Click Cancel

List-Based Fields

To change the value of some of the fields, you would use their combo box to display the available values. After clicking the arrow, a list would display:

Property Selection

There are various types of list-based fields. Some of them display just two items. To change their value, you can just double-click the field. Some other fields have more than two values in the field. To change them, you can click their arrow and select from the list. You can also double-click a few times until the desired value is selected.

ApplicationApplication: Checking List-based Fields

  1. Click an empty area of the form to select the form
  2. In the Properties window, click FormBorderStyle and notice that it displays an arrow button of a combo box
  3. Press Alt and the down arrow key to display the list
  4. Press Esc

Area-Selection Fields

Some properties provide a window from where you can select the desired option. The field primarily displays the arrow of a combo box. To use the field, you click the arrow of the combo box and the window appears. Here are examples:

Alignment Back Color

After expanding the window, you can select the desired option. We will eventually review them.

ApplicationApplication: Checking Area-Selection Fields

  1. On the form, click one of the controls
  2. In the Properties window, click Dock and click the arrow of its combo box
  3. Notice the window that comes up and press Esc
  4. On the main menu, click File -> Close Solution or File -> Close Project
  5. When asked whether you want to save, click Discard
 

Home Copyright © 2010# Key