This documentation is archived and is not being maintained.

ToolTip.SetToolTip Method

Associates ToolTip text with the specified control.

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

public void SetToolTip(
	Control control,
	string caption


Type: System.Windows.Forms.Control

The Control to associate the ToolTip text with.

Type: System.String

The ToolTip text to display when the pointer is on the control.

In addition to specifying the ToolTip text to display for a control, you can also use this method to modify the ToolTip text for a control. Calling the SetToolTip method more than once for a given control does not specify multiple ToolTip text to display for a control, but instead changes the current ToolTip text for the control. To determine the ToolTip text that is associated with a control at run time, use the GetToolTip method.

As a general rule the text used should be short; however, you can insert line breaks by using the \r\n escape character sequence. Ampersands (&) in the text are handled as described by the StripAmpersands property.

The following code example creates an instance of the ToolTip class and associates the instance with the Form that 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 be displayed 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 requires 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.

      // 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");

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0