ToolTip 類別

定義

表示小矩形快顯視窗 (Pop-Up Window),它會在使用者將指標停留在控制項上時,顯示控制項用途的簡短說明。

public ref class ToolTip sealed : System::ComponentModel::Component, System::ComponentModel::IExtenderProvider
public ref class ToolTip : System::ComponentModel::Component, System::ComponentModel::IExtenderProvider
public sealed class ToolTip : System.ComponentModel.Component, System.ComponentModel.IExtenderProvider
public class ToolTip : System.ComponentModel.Component, System.ComponentModel.IExtenderProvider
type ToolTip = class
    inherit Component
    interface IExtenderProvider
Public NotInheritable Class ToolTip
Inherits Component
Implements IExtenderProvider
Public Class ToolTip
Inherits Component
Implements IExtenderProvider
繼承
實作

範例

下列程式代碼範例會建立 類別的實例, ToolTip 並將 實例與 Form 實例建立所在的 相關聯。 然後,程式代碼會初始化延遲屬性 AutoPopDelayInitialDelayReshowDelay。 此外,類別的 ToolTip 實例會將 屬性設定 ShowAlwaystrue ,讓工具提示文字一律顯示,而不論表單是否為使用中。 最後,此範例會將 ToolTip 文字與表單上的兩個控制項建立關聯, Button 以及 CheckBox。 程式代碼範例會要求範例中定義的 方法位於 中包含FormButton名為 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

備註

透過 類別 ToolTip ,您可以在使用者將指標放在控件上時,向使用者提供提示。 類別 ToolTip 通常用來將使用者警示為控件的預定用途。 例如,您可以指定接受名稱之控件的工具提示文字 TextBox ,並指定要輸入控件之名稱的格式。 除了提供提示之外,您也可以使用 ToolTip 類別來提供運行時間狀態資訊。 例如,當使用者將指標PictureBox移至顯示因特網連線狀態的控件時,您可以使用 ToolTip 類別來顯示連線速度和線條質量數據。

類別 ToolTip 可用於任何容器。 若要明確指定容器,請使用 建 ToolTip(IContainer) 構函式。 單 ToolTip 一元件通常用來為單一窗體上的多個控件建立工具提示。 建立 ToolTip之後,請使用 方法的個別呼叫 SetToolTip ,將 ToolTip 顯示文字與個別控件產生關聯。 然後當用戶移動控件上的指標時,會顯示具有其文字的工具提示。 您可以為相同的控件呼叫 SetToolTip 一次以上,以變更與控件相關聯的文字。 若要取得與控件相關聯的文字,請使用 GetToolTip 方法。 若要移除所有工具提示文字與 類別實例的 ToolTip 關聯,請使用 RemoveAll 方法。

注意

停用的控件不會顯示工具提示文字。 ShowAlways除非 屬性設定true為 ,否則當容器處於非使用中狀態時,不會顯示工具提示。

類別 ToolTip 提供下列屬性和方法來修改工具提示的預設行為和外觀。

類別 相關聯的成員
手動顯示 Active, Show, Hide, ShowAlways, Popup, StopTimer
工具提示計時 AutoPopDelay, InitialDelay, ReshowDelay, AutomaticDelay, StopTimer
Content SetToolTip, GetToolTip, StripAmpersands, ToolTipIcon, ToolTipTitle, RemoveAll
外觀 BackColor, ForeColor, IsBalloon, OwnerDraw, UseAnimation, UseFading

如果您想要停用所有工具提示文字,使其無法顯示在應用程式中,您可以使用 Active 屬性。 工具提示通常是由作業系統繪製,但若要自定義 的外觀 ToolTip,您可以將 屬性設定 OwnerDrawtrue 並處理 Draw 事件。

類別ToolTipTitle會實作 System.ComponentModel.IExtenderProvider 介面,此介面具有單一方法 。 CanExtend 工具提示會在設計時間擴充相同窗體上的控制項,並新增 ToolTip 屬性。 如需擴充器提供者的詳細資訊,請參閱 擴充器提供者

建構函式

ToolTip()

不使用指定的容器,初始化 ToolTip 的新執行個體。

ToolTip(IContainer)

使用指定的容器,初始化 ToolTip 類別的新執行個體。

屬性

Active

取得或設定值,指出工具提示目前是否在作用中。

AutomaticDelay

取得或設定工具提示的自動延遲。

AutoPopDelay

取得或設定當指標靜止於含指定工具提示文字的控制項上時,工具提示保持可見的時間。

BackColor

取得或設定工具提示的背景色彩。

CanRaiseEvents

取得值,指出元件是否能引發事件。

(繼承來源 Component)
Container

取得包含 IContainerComponent

(繼承來源 Component)
CreateParams

取得工具提示視窗的建立參數。

DesignMode

取得值,指出 Component 目前是否處於設計模式。

(繼承來源 Component)
Events

取得附加在這個 Component 上的事件處理常式清單。

(繼承來源 Component)
ForeColor

取得或設定工具提示的前景色彩。

InitialDelay

取得或設定在工具提示出現之前,所經過的時間。

IsBalloon

取得或設定值,指出工具提示是否應該使用汽球樣式的視窗。

OwnerDraw

取得或設定值,指出要由作業系統繪製工具提示或是由您提供的程式碼繪製。

ReshowDelay

取得或設定當指標從某個控制項移動到另一個控制項時,在後續工具提示視窗出現之前,必須經過的時間長度。

ShowAlways

取得或設定值,指出即使父控制項為非現用時,是否也會顯示工具提示視窗。

Site

取得或設定 ComponentISite

(繼承來源 Component)
StripAmpersands

取得或設定值,以便判斷連字號 (&) 字元的處理方式。

Tag

取得或設定物件,其中含有與 ToolTip 關聯之程式設計人員提供的資料。

ToolTipIcon

取得或設定值,以便定義要顯示在工具提示文字旁的圖示類型。

ToolTipTitle

取得或設定工具提示視窗的標題。

UseAnimation

取得或設定值,以便判斷顯示工具提示時是否應該使用動畫效果。

UseFading

取得或設定值,以便判斷顯示工具提示時是否應該使用淡出效果。

方法

CanExtend(Object)

如果工具提示可以提供擴充項 (Extender) 屬性給指定的目標元件,則會傳回 true

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Dispose()

釋放 Component 所使用的所有資源。

(繼承來源 Component)
Dispose(Boolean)

釋放 Component 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

Dispose(Boolean)

釋放 Component 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

(繼承來源 Component)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
Finalize()

在記憶體回收行程回收 Cursor 之前,釋放 Unmanaged 資源並執行其他清除作業。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。

(繼承來源 Component)
GetToolTip(Control)

擷取與指定控制項相關的工具提示文字。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
Hide(IWin32Window)

隱藏指定的工具提示視窗。

InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
RemoveAll()

移除所有目前與工具提示元件相關聯的工具提示文字。

SetToolTip(Control, String)

建立工具提示文字與指定控制項的關聯。

Show(String, IWin32Window)

設定與指定之控制項相關聯的工具提示文字,並以強制回應方式顯示工具提示。

Show(String, IWin32Window, Int32)

設定與指定之控制項相關聯的工具提示文字,然後在指定的持續期限內顯示工具提示。

Show(String, IWin32Window, Int32, Int32)

設定與指定之控制項相關聯的工具提示文字,然後在指定的相對位置以強制回應方式顯示工具提示。

Show(String, IWin32Window, Int32, Int32, Int32)

設定與指定之控制項相關聯的工具提示文字,然後在指定的相對位置並於指定的持續期限內顯示工具提示。

Show(String, IWin32Window, Point)

設定與指定之控制項相關聯的工具提示文字,然後在指定的相對位置以強制回應方式顯示工具提示。

Show(String, IWin32Window, Point, Int32)

設定與指定之控制項相關聯的工具提示文字,然後在指定的相對位置並於指定的持續期限內顯示工具提示。

StopTimer()

停止隱藏顯示工具提示的計時器。

ToString()

傳回這個控制項的字串 (String) 表示。

事件

Disposed

Dispose() 方法的呼叫處置元件時,就會發生。

(繼承來源 Component)
Draw

繪製工具提示而且 OwnerDraw 屬性設定為 trueIsBalloon 屬性設定為 false 時發生。

Popup

發生於最初顯示工具提示之前。 此為 ToolTip 類別的預設事件。

適用於

另請參閱