Bagikan melalui


ToolTip.SetToolTip(Control, String) Metode

Definisi

Mengaitkan teks TipsAlat dengan kontrol yang ditentukan.

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

Control untuk mengaitkan teks TipsAlat dengan.

caption
String

Teks TipsAlat untuk ditampilkan saat penunjuk berada di kontrol.

Contoh

Contoh kode berikut membuat instans ToolTip kelas dan mengaitkan instans dengan Form instans yang dibuat di dalamnya. Kode kemudian menginisialisasi properti AutoPopDelaypenundaan , , InitialDelaydan ReshowDelay. Selain itu, instans ToolTipShowAlways kelas mengatur properti ke untuk true mengaktifkan teks TipsAlat untuk ditampilkan terlepas dari apakah formulir aktif. Terakhir, contoh mengaitkan teks TipsAlat dengan dua kontrol pada formulir, Button dan CheckBox. Contoh ini mengharuskan metode yang ditentukan dalam contoh terletak di dalam Form yang berisi Button kontrol bernama button1 dan CheckBox kontrol bernama checkBox1, dan bahwa metode dipanggil dari konstruktor 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

Keterangan

Selain menentukan teks TipsAlat yang akan ditampilkan untuk kontrol, Anda juga bisa menggunakan metode ini untuk mengubah teks TipsAlat untuk kontrol. Memanggil SetToolTip metode lebih dari sekali untuk kontrol tertentu tidak menentukan beberapa teks TipsAlat untuk ditampilkan untuk kontrol, melainkan mengubah teks TipsAlat saat ini untuk kontrol. Untuk menentukan teks TipsAlat yang terkait dengan kontrol pada durasi, gunakan GetToolTip metode .

Sebagai aturan umum, teks yang digunakan harus pendek; namun, Anda dapat menyisipkan hentian baris dengan menggunakan \r\n urutan karakter escape. Ampersands (&) dalam teks ditangani seperti yang dijelaskan oleh StripAmpersands properti .

Berlaku untuk

Lihat juga