Control Appearance and Behavior

A control’s appearance is set via the same set of basic properties used to control form appearance: Items such as ForeColor, BackColor, and Font make an appearance on most controls.

Visual Styles

One item of interest is the capability for a control to automatically alter its appearance to conform to the currently selected “Desktop Theme” if it’s running on Windows XP, Windows Vista, Windows 7, or Windows 8. This capability is enabled by a call to the Application.EnableVisualStyles method. This line of code is automatically included for you by default as the first line in the Main method. This location is ideal because it must be called before the controls in the application are actually created. If you remove the call, you can easily compare the appearance with and without the effects enabled. Figure 20.17 shows a form without visual styles enabled (left) alongside one with visual styles enabled (right).

Image

FIGURE 20.17 The effects of setting Application.EnableVisualStyles.

Tab Order

By default, the order in which the controls on a form receive focus (tab order) is the same as the order in which they were placed on the form. To explicitly set the tab order for all the controls on a form, the IDE has a tab order selection mode.

To enter tab order selection mode, select View, Tab Order from the menu. The Windows Forms Designer annotates every control on the form with a number. This number represents that control’s position within the overall tab order for the form. To set the tab order that you want, click sequentially on the controls; their tab order numbers automatically change as you click.

ToolTips

ToolTips are small “balloons” that display text as a user moves his cursor over a control. Typically, they are used to provide helpful hints or descriptions of a control’s purpose, action, and so on. ToolTips are implemented with the ToolTip class and can be assigned to controls at design time.

The ToolTip class is an example of an extender provider. (See the previous note on extender providers in our discussion on the TableLayoutPanel control.) When you add a ToolTip component to a form, every control on the form now implements a ToolTip property that is used to assign a ToolTip to that specific control.

For illustration, if you wanted to add a ToolTip to a ToolStrip button, you would first drag the ToolTip component over to the form from the Toolbox. You would then select the ToolStrip button that you want to add the ToolTip to, and you would set its ToolTip property to reference the ToolTip instance on your form.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset