ToolTips

In Chapter 2, we demonstrated tool tipsthe helpful text that appears when the mouse hovers over an item in a GUI. Recall that the tool tips displayed in Visual Studio help you become familiar with the IDE's features and serve as useful reminders for each toolbar icon's functionality. Many programs use tool tips to remind users of each control's purpose. For example, Microsoft Word has tool tips that help users determine the purpose of the application's icons. This section demonstrates how use the ToolTip component to add tool tips to your applications. Figure 13.31 describes common properties and a common event of class ToolTip.

Figure 13.31. ToolTip properties and events.

ToolTip properties and events

Description

Common Properties

AutoPopDelay

The amount of time (in milliseconds) that the tool tip appears while the mouse is over a control.

InitialDelay

The amount of time (in milliseconds) that a mouse must hover over a control before a tool tip appears.

ReshowDelay

The amount of time (in milliseconds) between which two different tool tips appear (when the mouse is moved from one control to another).

Common Event

Draw

Raised when the tool tip is displayed. This event allows programmers to modify the appearance of the tool tip.

When you add a ToolTip component from the Toolbox, it appears in the component traythe gray region below the Form in Design mode. Once a ToolTip is added to a Form, a new property appears in the Properties window for the Form's other controls. This property appears in the Properties window as ToolTip on, followed by the name of the ToolTip component. For instance, if our Form's ToolTip were named helpfulToolTip, you would set a control's ToolTip on helpfulToolTip property value to specify the control's tool tip text. Figure 13.32 demonstrates the ToolTip component. For this example, we create a GUI containing two Labels, so we can demonstrate different tool tip text for each Label. To make the sample outputs clearer, we set the BorderStyle property of each Label to FixedSingle, which displays a solid border. Since there is no event-handling code in this example, the class in Fig. 13.32 contains only a constructor.

Figure 13.32. Demonstrating the ToolTip component.

1 // Fig. 13.32: ToolTipExampleForm.cs 2 // Demonstrating the ToolTip component. 3 using System; 4 using System.Windows.Forms; 5 6 public partial class ToolTipExampleForm : Form 7 { 8 // default constructor 9 public ToolTipExampleForm() 10 { 11 InitializeComponent(); 12 } // end constructor 13 14 // no event handlers needed for this example 15 16 } // end class ToolTipExampleForm  

(a)

(b)

In this example, we named the ToolTip component labelsToolTip. Figure 13.33 shows the ToolTip in the component tray. We set the tool tip text for the first Label to "First Label" and the tool tip text for the second Label to "Second Label". Figure 13.34 demonstrates setting the tool tip text for the first Label.

Figure 13.33. Demonstrating the component tray.

Figure 13.34. Setting a control's tool tip text.

Категории