ToolTip.SetToolTip(Control, String) Метод

Определение

Связывает текст всплывающей подсказки с указанным элементом управления.

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)

Параметры

control
Control

Объект Control, с которым связывается текст всплывающей подсказки.

caption
String

Текст всплывающей подсказки, отображаемый, когда указатель оказывается над элементом управления.

Примеры

В следующем примере кода создается экземпляр ToolTip класса и он связывается с экземпляром Form , в рамках этого экземпляра создается. Затем код инициализирует свойства AutoPopDelayзадержки , InitialDelayи ReshowDelay. Кроме того, экземпляр класса задает свойству ToolTipShowAlways значение , true чтобы разрешить отображение текста подсказки независимо от того, активна ли форма. Наконец, в примере текст подсказки связывается с двумя элементами управления в форме: Button и CheckBox. В этом примере требуется, чтобы метод, определенный в примере, находился в Form объекте , который содержит Button элемент управления с именем button1 и CheckBox элемент управления с именем checkBox1, а метод вызывается из конструктора 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

Комментарии

Помимо указания текста подсказки, отображаемого для элемента управления, этот метод также можно использовать для изменения текста подсказки для элемента управления . При вызове SetToolTip метода несколько раз для данного элемента управления не указывается несколько текста подсказки для отображения элемента управления, а вместо этого изменяется текущий текст подсказки для элемента управления. Чтобы определить текст подсказки, связанный с элементом управления во время выполнения, используйте GetToolTip метод .

Как правило, используемый текст должен быть коротким; Однако разрывы строк можно вставить с помощью \r\n последовательности escape-символов. Амперсанды (&) в тексте обрабатываются, как описано свойством StripAmpersands .

Применяется к

См. также раздел