Freigeben über


ToolTip.SetToolTip(Control, String) Methode

Definition

Ordnet QuickInfo-Text dem angegebenen Steuerelement zu.

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)

Parameter

control
Control

Der Control QuickInfo-Text, dem der QuickInfo zugeordnet werden soll.

caption
String

Der QuickInfo-Text, der angezeigt werden soll, wenn sich der Zeiger auf dem Steuerelement befindet.

Beispiele

Im folgenden Codebeispiel wird eine Instanz der ToolTip Klasse erstellt und der Instanz zugeordnet, in der Form die Instanz erstellt wird. Der Code initialisiert dann die Verzögerungseigenschaften AutoPopDelay, InitialDelayund ReshowDelay. Darüber hinaus legt die Instanz der ToolTip Klasse die ShowAlways Eigenschaft so fest, dass true QuickInfo-Text unabhängig davon angezeigt werden kann, ob das Formular aktiv ist. Schließlich ordnet das Beispiel QuickInfo-Text zwei Steuerelementen in einem Formular, einem Button und einem Steuerelement CheckBoxzu. Dieses Beispiel erfordert, dass sich die im Beispiel definierte Methode in einem Form Steuerelement befindet, das ein Button Steuerelement namens button1 und ein CheckBox Steuerelement mit dem Namen checkBox1enthält, und dass die Methode vom Konstruktor der .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

Hinweise

Zusätzlich zum Angeben des QuickInfo-Texts, der für ein Steuerelement angezeigt werden soll, können Sie diese Methode auch verwenden, um den QuickInfo-Text für ein Steuerelement zu ändern. Das Aufrufen der SetToolTip Methode für ein bestimmtes Steuerelement gibt nicht mehrere QuickInfo-Text an, der für ein Steuerelement angezeigt werden soll, sondern ändert stattdessen den aktuellen QuickInfo-Text für das Steuerelement. Verwenden Sie die Methode, um den QuickInfo-Text zu bestimmen, der GetToolTip einem Steuerelement zur Laufzeit zugeordnet ist.

In der Regel sollte der verwendete Text kurz sein; Sie können jedoch Zeilenumbrüche mithilfe der \r\n Escapezeichenfolge einfügen. Ampersands (&) im Text werden wie in der StripAmpersands Eigenschaft beschrieben behandelt.

Gilt für:

Weitere Informationen