Share via


ToolTip.SetToolTip(Control, String) Metoda

Definice

Přidruží text popisku k zadanému ovládacímu prvku.

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)

Parametry

control
Control

Chcete-li Control přidružit text popisku.

caption
String

Text popisku, který se má zobrazit, když je ukazatel myši na ovládacím prvku.

Příklady

Následující příklad kódu vytvoří instanci ToolTip třídy a přidruží instanci k Form instanci, ve které je instance vytvořena. Kód pak inicializuje vlastnosti AutoPopDelayzpoždění , InitialDelaya ReshowDelay. Kromě toho instance ToolTip třídy nastaví ShowAlways vlastnost na true , aby bylo možné zobrazit text popisu bez ohledu na to, zda je formulář aktivní. Nakonec příklad přidruží text popisu ke dvěma ovládacím prvkům ve formuláři, Button a .CheckBox Tento příklad vyžaduje, aby se metoda definovaná v příkladu nacházela v objektu FormButton , který obsahuje ovládací prvek s názvem button1 a CheckBox ovládací prvek s názvem checkBox1a aby byla metoda volána z konstruktoru objektu 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

Poznámky

Kromě zadání textu popisku, který se má zobrazit pro ovládací prvek, můžete tuto metodu použít také k úpravě textu popisu pro ovládací prvek. SetToolTip Volání metody více než jednou pro daný ovládací prvek nezadá více text popisů, který se má zobrazit pro ovládací prvek, ale místo toho změní aktuální text popisu pro ovládací prvek. Chcete-li určit text popisku, který je přidružen k ovládacímu prvku za běhu, použijte metodu GetToolTip .

Obecně platí, že použitý text by měl být krátký; Konce řádků však můžete vložit pomocí \r\n řídicí sekvence znaků. Ampersandy (&) v textu se zpracovávají podle popisu StripAmpersands vlastnosti.

Platí pro

Viz také