Export (0) Print
Expand All

ToolTip.SetToolTip Method

Associates ToolTip text with the specified control.

[Visual Basic]
Public Sub SetToolTip( _
   ByVal control As Control, _
   ByVal caption As String _
)
[C#]
public void SetToolTip(
 Control control,
 string caption
);
[C++]
public: void SetToolTip(
 Control* control,
 String* caption
);
[JScript]
public function SetToolTip(
   control : Control,
 caption : String
);

Parameters

control
The Control to associate the ToolTip text with.
caption
The ToolTip text to display when the mouse cursor is over the control.

Remarks

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, you can use the GetToolTip method.

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 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 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

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

See Also

ToolTip Class | ToolTip Members | System.Windows.Forms Namespace | GetToolTip

Show:
© 2015 Microsoft