Export (0) Print
Expand All
4 out of 7 rated this helpful - Rate this topic

ToolTip Class

Represents a small rectangular pop-up window that displays a brief description of a control's purpose when the mouse hovers over the control.

For a list of all members of this type, see ToolTip Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.ToolTip

[Visual Basic]
NotInheritable Public Class ToolTip
   Inherits Component
   Implements IExtenderProvider
[C#]
public sealed class ToolTip : Component, IExtenderProvider
[C++]
public __gc __sealed class ToolTip : public Component,
   IExtenderProvider
[JScript]
public class ToolTip extends Component implements IExtenderProvider

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The ToolTip class allows you to provide help to users when they place the mouse cursor over a control. The ToolTip class is typically used to alert users to the intended use of a control. For example, you could specify ToolTip text for a TextBox control that accepts a name, specifying the format of the name to typed into the control. In addition to providing help, you can also use the ToolTip class to provide run time status information. For example, you could use the ToolTip class to display connection speed and line quality data when the user moves the mouse cursor over a PictureBox control that displays Internet connection status.

The ToolTip class provides properties that enable you to modify how long and how quickly a ToolTip window is displayed. The AutoPopDelay determines how long a ToolTip window is displayed; the InitialDelay and ReshowDelay properties determine the delay before a ToolTip window is displayed. To set all these properties to a consistent pattern, you can use the AutomaticDelay property. This value is then used to calculate and set the values of the other delay properties. To enable a control's ToolTip text to be displayed regardless of whether the Form or container the control is contained within is enabled, you can use the ShowAlways property. If you want to disable all ToolTip text from being displayed in your application, you can use the Active property.

The ToolTip class can be used in any container. To specify a specific container to use the ToolTip class within, use the ToolTip constructor. In order for ToolTip text to be displayed when the user moves the mouse cursor over a control, the ToolTip text to be displayed must be associated with the control within an instance of the ToolTip class. To associate ToolTip text with a control, use the SetToolTip method. The SetToolTip method can be called more than once for the same control to change the text that is associated with the control. If you want to get the text that is associated with a control, use the GetToolTip method. To remove all ToolTip text associations with an instance of the ToolTip class, use the RemoveAll method.

Note   ToolTip text is not displayed for controls that are disabled.

Example

[Visual Basic, C#, C++] The following example creates an instance of the ToolTip class and associates it with the Form the instance is created within. The code then initializes the delay properties AutoPopDelay, InitialDelay, and ReshowDelay. In addition the instance of the ToolTip class sets the ShowAlways property to true to enable ToolTip text to always be display regardless of whether the form is active. Finally, the example associates ToolTip text with two controls on a form, a Button and a CheckBox. This example assumes that the method defined in the example is located within a Form that contains a Button control named button1 and a CheckBox control named checkBox1 and that the method is called from the constructor of the Form.

[Visual Basic] 
' This example assumes that the Form_Load event handling method
' is connected to the Load event of the form.
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
   ' Create the ToolTip and associate with the Form container.
   Dim toolTip1 As New ToolTip()
   
   ' Set up the delays for the ToolTip.
   toolTip1.AutoPopDelay = 5000
   toolTip1.InitialDelay = 1000
   toolTip1.ReshowDelay = 500
   ' Force the ToolTip text to be displayed whether or not the form is active.
   toolTip1.ShowAlways = True
   
   ' Set up the ToolTip text for the Button and Checkbox.
   toolTip1.SetToolTip(Me.button1, "My button1")
   toolTip1.SetToolTip(Me.checkBox1, "My checkBox1")
End Sub

[C#] 
// This example assumes that the Form_Load event handling method
// is connected to the Load event of the form.
private void Form1_Load(object sender, System.EventArgs e)
{
   // Create the ToolTip and associate with the Form container.
   ToolTip toolTip1 = new ToolTip();

   // Set up the delays for the ToolTip.
   toolTip1.AutoPopDelay = 5000;
   toolTip1.InitialDelay = 1000;
   toolTip1.ReshowDelay = 500;
   // Force the ToolTip text to be displayed whether or not the form is active.
   toolTip1.ShowAlways = true;
      
   // Set up the ToolTip text for the Button and Checkbox.
   toolTip1.SetToolTip(this.button1, "My button1");
   toolTip1.SetToolTip(this.checkBox1, "My checkBox1");
}

[C++] 
// This example assumes that the Form_Load event handling method
// is connected to the Load event of the form.
private:
void Form1_Load(Object* /*sender*/, System::EventArgs* /*e*/)
{
   // Create the ToolTip and associate with the Form container.
   ToolTip* toolTip1 = new ToolTip();

   // Set up the delays for the ToolTip.
   toolTip1->AutoPopDelay = 5000;
   toolTip1->InitialDelay = 1000;
   toolTip1->ReshowDelay = 500;
   // Force the ToolTip text to be displayed whether or not the form is active.
   toolTip1->ShowAlways = true;
      
   // Set up the ToolTip text for the Button and Checkbox.
   toolTip1->SetToolTip(this->button1, S"My button1");
   toolTip1->SetToolTip(this->checkBox1, S"My checkBox1");
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

ToolTip Members | System.Windows.Forms Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.