ToolTip.SetToolTip(Control, String) Metoda

Definicja

Kojarzy tekst etykietki narzędzia z określoną kontrolką.

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

Element Control do skojarzenia tekstu etykietki narzędzia z.

caption
String

Tekst etykietki narzędzia do wyświetlenia, gdy wskaźnik znajduje się w kontrolce.

Przykłady

Poniższy przykład kodu tworzy wystąpienie ToolTip klasy i kojarzy wystąpienie z Form wystąpieniem, w ramach którego jest tworzone wystąpienie. Następnie kod inicjuje właściwości AutoPopDelayopóźnienia , InitialDelayi ReshowDelay. Ponadto wystąpienie ToolTip klasy ustawia ShowAlways właściwość w celu true włączenia wyświetlania tekstu etykietki narzędzia niezależnie od tego, czy formularz jest aktywny. Na koniec przykład kojarzy tekst etykietki narzędzia z dwoma kontrolkami w formularzu, a Button i .CheckBox Ten przykład wymaga, aby metoda zdefiniowana w przykładzie znajdowała się w obiekcie Form zawierającym kontrolkę Button o nazwie i kontrolce CheckBox o nazwie checkBox1button1 , a metoda jest wywoływana z konstruktora Formklasy .

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

Uwagi

Oprócz określenia tekstu etykietki narzędzia do wyświetlenia dla kontrolki można również użyć tej metody, aby zmodyfikować tekst etykietki narzędzia dla kontrolki. SetToolTip Wywołanie metody więcej niż raz dla danej kontrolki nie określa wielu tekstu etykietki narzędzia do wyświetlenia dla kontrolki, ale zamiast tego zmienia bieżący tekst etykietki narzędzia dla kontrolki. Aby określić tekst etykietki narzędzia skojarzony z kontrolką w czasie wykonywania, użyj GetToolTip metody .

Ogólnie rzecz biorąc, używany tekst powinien być krótki; można jednak wstawić podziały wierszy przy użyciu \r\n sekwencji znaków ucieczki. Ampersands (&) w tekście są obsługiwane zgodnie z opisem StripAmpersands właściwości.

Dotyczy

Zobacz też