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を初期化します。 さらに、 クラスのToolTipインスタンスは、 プロパティを にtrue設定ShowAlwaysして、フォームがアクティブかどうかに関係なく、ツールヒント テキストを表示できるようにします。 最後に、ツールヒント テキストをフォーム Button の 2 つのコントロール ( と CheckBox) に関連付けます。 この例では、この例で定義されているメソッドが、 という名前のコントロールと CheckBox という名前button1checkBox1のコントロールを含む ButtonFormにあり、 メソッドが の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 挿入できます。 テキスト内のアンパサンド (&) は、 プロパティで StripAmpersands 説明されているように処理されます。

適用対象

こちらもご覧ください