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 實例建立所在的 相關聯。 然後,程式代碼會初始化延遲屬性 AutoPopDelayInitialDelayReshowDelay。 此外,類別的 ToolTip 實例會將 ShowAlways 屬性設定為 true ,以允許顯示工具提示文字,而不論表單是否為使用中。 最後,此範例會將 ToolTip 文字與表單上的兩個CheckBox控件產生關聯,Button以及 。 這個範例要求範例中定義的 方法位於 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針對指定的控件呼叫 方法一次以上,並不會為控件指定要顯示的多個 ToolTip 文字,而是改為變更控件目前的 ToolTip 文字。 若要判斷在運行時間與控件相關聯的工具提示文字,請使用 GetToolTip 方法。

作為一般規則,使用的文字應該很短;不過,您可以使用逸出字元序列來插入換行符 \r\n 。 文字中的 ampersands (&) 會依照 屬性所述 StripAmpersands 處理。

適用於

另請參閱