Friday, March 14, 2008

Tooltips in VB.NET

One nice feature of VB.NET is the ease in which you can implement tooltips for any Control on the desktop (unfortunatley not for .NET CF, see here).

Define a global variable for the tooltip object:

Dim g_toolTip As ToolTip = Nothing

Initialize the tooltip object. There are several settings that can be initialized too:

g_toolTip = New ToolTip()
g_toolTip.AutoPopDelay = 5000
g_toolTip.InitialDelay = 1000
g_toolTip.ReshowDelay = 500
g_toolTip.ShowAlways = True


When you are ready to display a tooltip, you must specify the control that the tooltip is associated with (ctrl in my example). The control is any object derived from Control, so if you make your own .NET control (deriving it from the Control base class), it can be associated with the tooltip. You can also use existing controls like Button and PictureBox.

g_toolTip.SetToolTip(ctrl, "tooltip text")
g_toolTip.Active = True



This functionality is actually documented pretty well in the Microsoft documentation. There are also C# example and detailed descriptions of the options like AutoPopDelay.

3 comments:

Anonymous said...

Thank you, it's been usefull for me.

Tanmay Chakrabarty said...

Thanks buddy, it helped.

Anonymous said...

This is great stuff, thanks for sharing with us. It's help me lot and this link
http://www.mindstick.com/Articles/ec874100-4fcb-4dbd-8f6f-c600e61773e6/?ToolTip%20Control%20in%20VB.Net
also helped me lot in completing my project.

thanks !!!!