Бөлісу құралы:


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задержки и InitialDelayReshowDelay. Кроме того, экземпляр ToolTip класса задает ShowAlways свойство для true включения отображения текста подсказки независимо от того, активна ли форма. Наконец, в примере сопоставляется текст подсказки с двумя элементами управления в форме, a Button и a 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 .

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

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