ToolTip.SetToolTip(Control, String) Metod

Definition

Associerar Knappbeskrivningstext med den angivna kontrollen.

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)

Parametrar

control
Control

Associera Control knappbeskrivningstexten med.

caption
String

Knappbeskrivningstexten som ska visas när pekaren finns på kontrollen.

Exempel

I följande kodexempel skapas en instans av ToolTip klassen och instansen associeras med Form den som instansen skapas i. Koden initierar sedan fördröjningsegenskaperna AutoPopDelay, InitialDelayoch ReshowDelay. Dessutom anger ToolTip instansen ShowAlways av klassen egenskapen till true så att Knappbeskrivningstext kan visas oavsett om formuläret är aktivt. Slutligen associerar exemplet ToolTip-text med två kontroller i ett formulär, en Button och en CheckBox. Det här exemplet kräver att metoden som definieras i exemplet finns inom en Form som innehåller en Button kontroll med namnet button1 och en CheckBox kontroll med namnet checkBox1, och att metoden anropas från konstruktorn i 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

Kommentarer

Förutom att ange knappbeskrivningstexten som ska visas för en kontroll kan du också använda den här metoden för att ändra knappbeskrivningstexten för en kontroll. SetToolTip Att anropa metoden mer än en gång för en viss kontroll anger inte flera knappbeskrivningstexter som ska visas för en kontroll, utan ändrar i stället den aktuella Knappbeskrivningstexten för kontrollen. Använd metoden för att fastställa knappbeskrivningstexten som är associerad med en kontroll vid körning.GetToolTip

Som en allmän regel bör den text som används vara kort; Du kan dock infoga radbrytningar med hjälp \r\n av escape-teckensekvensen. Et&erna (&) i texten hanteras enligt beskrivningen av egenskapen StripAmpersands .

Gäller för

Se även