ToolTip Support for Visual Basic 6.0 Users
The methods for displaying ToolTips differ considerably between Visual Basic 6.0 and Visual Basic 2008.
In Visual Basic 6.0, the ToolTipText property of a control is used to display a ToolTip at run time.
In Visual Basic 2008, a single ToolTip component can be used to control the ToolTips for all controls on a form; the ToolTip component can be added to a form from the Toolbox. The SetToolTip method is used to set the text for each ToolTip based on the name of the control.
In Visual Basic 6.0, if the ToolTipText property contains text, the ToolTip is displayed; if it is empty, no ToolTip is displayed. To clear the text of multiple ToolTips, you need to loop through the Controls collection and set the ToolTipText property to an empty string.
In Visual Basic 2008, you can prevent the ToolTip from being displayed by passing an empty string to the SetToolTip method; you can clear the text of all ToolTips associated with a ToolTip component by setting the Active property to false.
In Visual Basic 6.0, there is no way to customize a ToolTip without resorting to Windows API calls.
In Visual Basic 2008, there are a number of new properties that allow you to customize the appearance or behavior of a ToolTip—for example, changing the colors, setting a delay before displaying a ToolTip, or creating multi-line ToolTips.
Code Changes for ToolTips
The following code examples illustrate the differences in coding techniques between Visual Basic 6.0 and Visual Basic 2008.
Code Changes for Displaying a ToolTip
The following example demonstrates setting a ToolTip for a Button control in Visual Basic 6.0 and Visual Basic 2008. The Visual Basic 2008 example assumes that a ToolTip component was added to the form at design time.
' Visual Basic 6.0 Button1.ToolTipText = "Save changes"
' Visual Basic ToolTip1.SetToolTip(Button1, "Save changes")
Code Changes for Hiding a ToolTip
The following example demonstrates hiding a ToolTip for a Button control in Visual Basic 6.0 and Visual Basic 2008. The Visual Basic 2008 example assumes that a ToolTip component was added to the form at design time.
The Visual Basic 2008 ToolTip component also has an Active property; setting this property to false will hide the ToolTips for all controls associated with that ToolTip component.
' Visual Basic 6.0 ' Hide a single ToolTip. Button1.ToolTipText = "" ' Hide all ToolTips. For Each Control in Me.Controls Control.ToolTipText = "" Next
' Visual Basic' Hide a single ToolTip. ToolTip1.SetToolTip(Button1, "") ' Hide all ToolTips. ToolTip1.Active = False
When a Visual Basic 6.0 is upgraded to Visual Basic 2008, any references to the ToolTipText property at either design time or run time are not upgraded, and comments are inserted into your code. A ToolTip component named ToolTip1 is added to your form; you will need to hook up your ToolTips by either setting the ToolTip on ToolTip1 property at design time or calling the SetToolTip method at run time.
If the Visual Basic 6.0 application uses Windows API calls to customize ToolTips, you should modify your code to take advantage of the customization features of the ToolTip component.