Partager via


ToolTip.SetToolTip(Control, String) Méthode

Définition

Associe du texte info-bulle au contrôle spécifié.

public:
 void SetToolTip(System::Windows::Forms::Control ^ control, System::String ^ caption);
public void SetToolTip(System.Windows.Forms.Control control, string caption);
public void SetToolTip(System.Windows.Forms.Control control, string? caption);
member this.SetToolTip : System.Windows.Forms.Control * string -> unit
Public Sub SetToolTip (control As Control, caption As String)

Paramètres

control
Control

Pour Control associer le texte d’info-bulle.

caption
String

Texte d’info-bulle à afficher lorsque le pointeur se trouve sur le contrôle.

Exemples

L’exemple de code suivant crée une instance de la ToolTip classe et associe l’instance à celle Form dans laquelle l’instance est créée. Le code initialise ensuite les propriétés AutoPopDelayde délai, InitialDelayet ReshowDelay. En outre, l’instance de la ToolTip classe définit la ShowAlways propriété pour permettre au true texte Info-bulle d’être affiché, que le formulaire soit actif ou non. Enfin, l’exemple associe du texte info-bulle à deux contrôles sur un formulaire, un Button et un CheckBox. Cet exemple nécessite que la méthode définie dans l’exemple se trouve dans un Form contrôle qui contient un Button contrôle nommé button1 et un CheckBox contrôle nommé checkBox1, et que la méthode est appelée à partir du constructeur du Form.

// This example assumes that the Form_Load event handling method
// is connected to the Load event of the form.
void Form1_Load( Object^ sender, System::EventArgs^ e )
{
   // Create the ToolTip and associate with the Form container.
   ToolTip^ toolTip1 = gcnew 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" );
}
// 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");
}
' 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

Remarques

Outre la spécification du texte info-bulle à afficher pour un contrôle, vous pouvez également utiliser cette méthode pour modifier le texte info-bulle d’un contrôle. L’appel de la SetToolTip méthode plusieurs fois pour un contrôle donné ne spécifie pas plusieurs info-bulles à afficher pour un contrôle, mais modifie plutôt le texte d’info-bulle actuel du contrôle. Pour déterminer le texte d’info-bulle associé à un contrôle au moment de l’exécution, utilisez la GetToolTip méthode.

En règle générale, le texte utilisé doit être court ; Toutefois, vous pouvez insérer des sauts de ligne à l’aide de la séquence de caractères d’échappement \r\n . Les ampersands (&) dans le texte sont gérés comme décrit par la StripAmpersands propriété.

S’applique à

Voir aussi