Building Applications with Visual Studio 2010 : Getting Smart about Smart Clients - Using the Properties Window

2/25/2013 6:40:43 PM

Every control has a set of properties and events that define how the control acts when your application runs. For example, the button control's Text property specifies the text that's displayed on the button. The button control has a Click event that's executed each time a user clicks the button.

The Visual Studio Properties window displays a control's properties and events in a grid, as shown in Figure 1.

Figure 1. Setting a control's properties and events.

The Properties window is open by default. If you close the Properties window at some point, you have two options for opening it again:

  • Choose View=>Properties Window

  • Press F4

The Properties window has the following elements:

  • A drop-down list at the top displays the selected control. Use the list to select a control to view.

  • A toolbar changes the view settings. Your view-setting choices are, from left to right

    • Categorized: Properties appear in groups

    • Alphabetical: Properties are sorted in alphabetical order

    • Properties: The control's properties are displayed

    • Events: The control's events are displayed

  • Two columns display the name-value pairs of the control's properties or events, depending on the view setting.

  • A brief description of the selected property or event appears at the bottom of the window.

The Properties window is a visual tool that organizes and categorizes the thousands of properties and events available for manipulating controls. You use the Properties window for two tasks:

  • Set a control's properties.

  • Create event handlers for a control.

When you use the Properties window, Visual Studio generates the code to set the control's properties and create event handlers. You can do all these tasks by using code, although it's much easier to use Visual Studio.

You can access thousands of properties and events by using the Properties window. Visual Studio groups properties and events into categories so that they're easier to manage. The following list describes the properties and events categories:

  • Action: Creates handlers for events, such as Click and Scroll.

  • Accessibility: Sets properties that make controls accessible to people with disabilities and makes the application easier to use for everyone.

  • Appearance: Contains properties related to font, color, border, and cursor style. The Text property and text-formatting properties are in this group.

  • Behavior: Contains properties and events related to how a control acts. Examples include Sorted, TabStop, and SelectedIndexChanged.

  • Data: Sets a control's data source, gets items selected in a control, and responds to changes in the data.

  • Design: Contains design-time properties, such as whether controls are locked. The Name property is here, too.

  • DragDrop: Responds to events related to dragging and dropping controls.

  • Focus: Captures events related to how the control gains and loses focus.

  • Key: Responds to keyboard-related events.

  • Layout: Sets layout properties, such as anchor, margin, and size.

  • Mouse: Responds to mouse events, such as MouseUp.

  • WindowStyle: Sets properties that define the Windows Form itself.

Within each control are properties that you can set. Here are some common properties that many controls share:

  • Name: Sets the identifier used to reference the control in code.

  • Text: Sets the text displayed in the control.

To set the access key for a control, add an ampersand (&) in front of the letter to use as the access key in the Text property. For example, to set the letter P in Print as the access key, set the Text property for the control equal to &Print. A user can then press the Alt key in combination with the access key to execute the control.


Windows Forms are controls. You access the properties of a Windows Forms control the same way you access the properties for any control. Here are the common properties for Windows Forms:

  • Text: Sets the text displayed on the form's title bar.

  • DefaultButton: Sets the button that responds to the Enter key by default.

  • CancelButton: Sets the button that responds to the Esc key by default.

  • MainMenuStrip: Sets the primary menu control for the form.

In addition to the controls you use to customize your forms, you have events to consider. Events are actions that your application might handle or respond to. Examples of common events include

  • Click

  • KeyDown

  • Load

  • ValueChanged

You can get context-sensitive help for any property or event you see in the Properties window by positioning your cursor in the value field for the property or event, and pressing F1.

1. Setting properties

Properties are expressed as name-value pairs. A property's value isn't always as simple as color=black. Values can be complex. You can use the selectors, wizards, and ellipses on the Visual Studio Properties page to dynamically build complex property values.

Examples of complex properties include properties related to

  • Setting data sources

  • Editing collections of items

  • Applying fonts and formatting

  • Selecting images and files

To set properties for a control on a Windows Form, follow these steps:

  1. Click the control in the forms designer.

  2. Press F4 to display the Properties window.

    The control's name and type appear on the drop-down list at the top of the Properties window.

  3. Click the Properties button on the Properties window's toolbar to display a list of the control's properties.

    The Properties button is the third toolbar button from the left.

  4. Scroll down the properties list and enter property values.

    You can type simple property values or select them from a drop-down list. Click the ellipsis button for more complex properties, such as collections to display a dialog box that builds the property, as shown in Figure 2. Click the plus sign (+) next to compound properties to set individual properties.

Figure 2. Click the ellipsis button to build complex properties.

2. Responding to events

The Visual Studio Properties window displays a control's events. For example, when a user clicks a button, the button's Click event occurs. You can use event handlers to write code that fires each time the event fires.

To set an event handler by using the Properties window, follow these steps:

  1. Select a form's control by clicking the control.

  2. In the Properties window, click the Events button to display the control's events.

    To create an event handler by using a default name, either press Enter without typing a name or double-click the field for the name.

    Double-click a control on the Windows Forms Designer to create the control's default event handler.

  3. Type a name for the event handler next to the event and press Enter.

    Visual Studio creates the event handler and opens the code editor to the event handler.

Video tutorials
- How To Install Windows 8

- How To Install Windows Server 2012

- How To Install Windows Server 2012 On VirtualBox

- How To Disable Windows 8 Metro UI

- How To Install Windows Store Apps From Windows 8 Classic Desktop

- How To Disable Windows Update in Windows 8

- How To Disable Windows 8 Metro UI

- How To Add Widgets To Windows 8 Lock Screen

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010
programming4us programming4us