Recipe 14.13. Adding Tooltips to Controls


Problem

You want a tooltip to appear when the user hovers the cursor (mouse) over a control.

Solution

Use the ToolTip control, included in the Windows Forms Toolbox, on your form. Figure 14-9 shows the ToolTip control in the Toolbox and applied to the form.

Figure 14-9. The ToolTip control added to a form


Discussion

When applied to a form, the ToolTip control enhances all displayable on-form controls, adding a new pseudoproperty to the properties collection of each control. If you add a ToolTip control named ToolTip1 to the form, each visible control includes a new "ToolTip on ToolTip1" property. For a specific control, fill this pseudoproperty with the text to display in the tooltip. Figure 14-10 shows a tooltip in use on a running form.

Figure 14-10. A tooltip in use


Normally, adding a single ToolTip control to a form is sufficient for all your tooltip display needs. While each control communicates its own tooltip display text through the added ToolTip pseudoproperty, the ToolTip control itself manages how that text gets displayed, through its own property settings. For instance, the IsBalloon property, when set to true, displays the tooltip in a balloon display instead of a plain square (see Figure 14-11).

Figure 14-11. A balloon-shaped tooltip


You can also take full control of the drawing of the tooltip by setting its OwnerDraw property to TRue and responding to the control's Draw event. See Chapter 9 for examples of drawing to a custom graphics surface.

See Also

Recipe 14.11 shows how to add tooltips to notification icons in the System Tray.




Visual Basic 2005 Cookbook(c) Solutions for VB 2005 Programmers
Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))
ISBN: 0596101775
EAN: 2147483647
Year: 2006
Pages: 400

Similar book on Amazon

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