Tooltip In C#

A tooltip is a small pop-up window that displays some information when you rollover on a control.

In this article, I will discuss how to create and use a Tooltip control in a Windows Forms application using Visual Studio 2010. After that, I will discuss various properties and methods available for the Tooltip control.

Creating a Tooltip

Tooltip class represents a tooltip control. Once a Tooltip object is created, we need to call SetToolTip method and pass a control and text. The following code snippet creates a Tooltip and attaches to a Button control using SetToolTip method.
  1. ToolTip toolTip1 = newToolTip();  
  2. toolTip1.ShowAlways = true;  
  3. toolTip1.SetToolTip(button1, "Click me to execute.");  
If you rollover on Button control, you will see the following output.
 
ToolTipImg1.jpg
Figure 1
 
Tooltip Properties
  • Active - A tooltip is currently active.
  • AutomaticDelay - Automatic delay for the tooltip.
  • AutoPopDelay - The period of time the ToolTip remains visible if the pointer is stationary on a control with specified ToolTip text.
  • InitialDelay - Gets or sets the time that passes before the ToolTip appears.
  • IsBaloon - Gets or sets a value indicating whether the ToolTip should use a balloon window.
  • ReshowDelay - Gets or sets the length of time that must transpire before subsequent ToolTip windows appear as the pointer moves from one control to another.
  • ShowAlways - Displays if tooltip is displayed even if the parent control is not active.
  • ToolTipIcon - Icon of tooltip window.
  • ToolTipTitle - Title of tooltip window.
  • UseAnimation - Represents whether an animation effect should be used when displaying the tooltip.
  • UseFading - Represents whether a fade effect should be used when displaying the tooltip.
The following code snippet sets some of these properties.
  1. ToolTip buttonToolTip = newToolTip();  
  2. buttonToolTip.ToolTipTitle = "Button Tooltip";  
  3. buttonToolTip.UseFading = true;  
  4. buttonToolTip.UseAnimation = true;  
  5. buttonToolTip.IsBalloon = true;  
  6. buttonToolTip.ShowAlways = true;  
  7. buttonToolTip.AutoPopDelay = 5000;  
  8. buttonToolTip.InitialDelay = 1000;  
  9. buttonToolTip.ReshowDelay = 500;  
  10. buttonToolTip.SetToolTip(button1, "Click me to execute.");  
Balloon Tooltip

By setting IsBalloon to true it makes a tooltip balloon that looks like Figure 2.
 
ToolTipImg2.jpg
Figure 2
 
Summary

In this article, we discussed how to create a Tooltip control in Windows Forms and set its various properties.


Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.