ToolTip 類別

定義

表示小矩形快顯視窗 (Pop-Up Window),它會在使用者將指標停留在控制項上時,顯示控制項用途的簡短說明。Represents a small rectangular pop-up window that displays a brief description of a control's purpose when the user rests the pointer on the control.

public ref 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 Class ToolTip
Inherits Component
Implements IExtenderProvider
繼承
實作

範例

下列程式碼範例會建立 ToolTip 類別的實例,並將實例與在其中建立實例的 Form 產生關聯。The following code example creates an instance of the ToolTip class and associates the instance with the Form that the instance is created within. 然後,此程式碼會將延遲屬性初始化 AutoPopDelayInitialDelayReshowDelayThe code then initializes the delay properties AutoPopDelay, InitialDelay, and ReshowDelay. 此外,ToolTip 類別的實例會將 ShowAlways 屬性設定為 true,讓工具提示文字一律會顯示,不論表單是否作用中。In addition the instance of the ToolTip class sets the ShowAlways property to true to enable ToolTip text to always be display regardless of whether the form is active. 最後,此範例會將工具提示文字與表單上的兩個控制項、ButtonCheckBox產生關聯。Finally, the example associates ToolTip text with two controls on a form, a Button and a CheckBox. 此程式碼範例會要求在範例中定義的方法,位於包含名為 button1Button 控制項和名為 checkBox1CheckBox 控制項的 Form 中,而且會從 Form的函式呼叫方法。The code example requires that the method defined in the example is located within a Form that contains a Button control named button1 and a CheckBox control named checkBox1, and that the method is called from the constructor of the 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 類別,您可以在使用者將指標放在控制項上時,為使用者提供提示。With the ToolTip class, you can provide hints to a user when the user places the pointer on a control. ToolTip 類別通常用來警示使用者使用控制項的意圖。The ToolTip class is typically used to alert users to the intended use of a control. 例如,您可以指定接受名稱之 TextBox 控制項的工具提示文字,指定要在控制項中輸入的名稱格式。For example, you can specify ToolTip text for a TextBox control that accepts a name, specifying the format of the name to be typed into the control. 除了提供提示之外,您也可以使用 ToolTip 類別來提供執行時間狀態資訊。In addition to providing hints, you can also use the ToolTip class to provide run time status information. 例如,當使用者將指標移至顯示網際網路線上狀態的 PictureBox 控制項時,您可以使用 ToolTip 類別來顯示連線速度和行品質資料。For example, you can use the ToolTip class to display connection speed and line quality data when the user moves the pointer onto a PictureBox control that displays Internet connection status.

ToolTip 類別可以在任何容器中使用。The ToolTip class can be used in any container. 若要明確指定容器,請使用 ToolTip(IContainer) 的「構造函式」。To explicitly specify a container, use the ToolTip(IContainer) constructor. 單一 ToolTip 元件通常用來在單一表單上建立多個控制項的工具提示。A single ToolTip component typically is used to create ToolTips for multiple controls on a single form. 建立 ToolTip之後,請使用 SetToolTip 方法的個別呼叫,將工具提示顯示文字與個別控制項產生關聯。After you create a ToolTip, use a separate call to the SetToolTip method to associate ToolTip display text to an individual control. 然後當使用者將指標移至控制項上時,就會顯示其文字的工具提示。Then when the user moves the pointer on a control, the ToolTip with its text is displayed. 您可以對同一個控制項呼叫 SetToolTip 一次以上,以變更與控制項相關聯的文字。You can call SetToolTip more than once for the same control to change the text that is associated with the control. 若要取得與控制項相關聯的文字,請使用 GetToolTip 方法。To get the text that is associated with a control, use the GetToolTip method. 若要移除與 ToolTip 類別之實例的所有工具提示文字關聯,請使用 RemoveAll 方法。To remove all ToolTip text associations with an instance of the ToolTip class, use the RemoveAll method.

注意

已停用的控制項不會顯示工具提示文字。ToolTip text is not displayed for controls that are disabled. 除非 [ShowAlways] 屬性設定為 [true],否則當其容器處於非作用中狀態時,不會顯示工具提示。Unless the ShowAlways property is set to true, ToolTips are not displayed when their container is inactive.

ToolTip 類別提供下列屬性和方法,以修改工具提示的預設行為和外觀。The ToolTip class provides the following properties and methods to modify the default behavior and appearance of a ToolTip.

CategoryCategory 相關聯的成員Associated members
手動顯示Manual display Active, Show, Hide, ShowAlways, Popup, StopTimerActive, Show, Hide, ShowAlways, Popup, StopTimer
工具提示時間ToolTip timing AutoPopDelay, InitialDelay, ReshowDelay, AutomaticDelay, StopTimerAutoPopDelay, InitialDelay, ReshowDelay, AutomaticDelay, StopTimer
內容Content SetToolTip, GetToolTip, StripAmpersands, ToolTipIcon, ToolTipTitle, RemoveAllSetToolTip, GetToolTip, StripAmpersands, ToolTipIcon, ToolTipTitle, RemoveAll
外觀Appearance BackColor, ForeColor, IsBalloon, OwnerDraw, UseAnimation, UseFadingBackColor, ForeColor, IsBalloon, OwnerDraw, UseAnimation, UseFading

如果您想要停用所有工具提示文字,使其無法顯示在您的應用程式中,您可以使用 [Active] 屬性。If you want to disable all ToolTip text so that it cannot be displayed in your application, you can use the Active property. 通常,工具提示是由作業系統所繪製,但是若要自訂 ToolTip的外觀,您可以將 OwnerDraw 屬性設定為 true 並處理 Draw 事件。Usually the ToolTip is drawn by the operating system, but to customize the appearance of the ToolTip, you can set the OwnerDraw property to true and handle the Draw event.

ToolTipTitle 類別會實 System.ComponentModel.IExtenderProvider 介面,其具有單一方法 CanExtendThe ToolTipTitle class implements the System.ComponentModel.IExtenderProvider interface, which has a single method, CanExtend. 工具提示會在設計階段將控制項延伸至相同的表單,並加入 ToolTip 屬性。ToolTips extend controls on the same form at design time, adding a ToolTip property. 如需有關擴充項提供者的詳細資訊,請參閱擴充項提供者For more information about extender providers, see Extender Providers.

建構函式

ToolTip()

不使用指定的容器,初始化 ToolTip 的新執行個體。Initializes a new instance of the ToolTip without a specified container.

ToolTip(IContainer)

使用指定的容器,初始化 ToolTip 類別的新執行個體。Initializes a new instance of the ToolTip class with a specified container.

屬性

Active

取得或設定值,指出工具提示目前是否在作用中。Gets or sets a value indicating whether the ToolTip is currently active.

AutomaticDelay

取得或設定工具提示的自動延遲。Gets or sets the automatic delay for the ToolTip.

AutoPopDelay

取得或設定當指標靜止於含指定工具提示文字的控制項上時,工具提示保持可見的時間。Gets or sets the period of time the ToolTip remains visible if the pointer is stationary on a control with specified ToolTip text.

BackColor

取得或設定工具提示的背景色彩。Gets or sets the background color for the ToolTip.

CanRaiseEvents

取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

(繼承來源 Component)
Container

取得包含 IContainerComponentGets the IContainer that contains the Component.

(繼承來源 Component)
CreateParams

取得工具提示視窗的建立參數。Gets the creation parameters for the ToolTip window.

DesignMode

取得值,指出 Component 目前是否處於設計模式。Gets a value that indicates whether the Component is currently in design mode.

(繼承來源 Component)
Events

取得附加在這個 Component 上的事件處理常式清單。Gets the list of event handlers that are attached to this Component.

(繼承來源 Component)
ForeColor

取得或設定工具提示的前景色彩。Gets or sets the foreground color for the ToolTip.

InitialDelay

取得或設定在工具提示出現之前,所經過的時間。Gets or sets the time that passes before the ToolTip appears.

IsBalloon

取得或設定值,指出工具提示是否應該使用汽球樣式的視窗。Gets or sets a value indicating whether the ToolTip should use a balloon window.

OwnerDraw

取得或設定值,指出要由作業系統繪製工具提示或是由您提供的程式碼繪製。Gets or sets a value indicating whether the ToolTip is drawn by the operating system or by code that you provide.

ReshowDelay

取得或設定當指標從某個控制項移動到另一個控制項時,在後續工具提示視窗出現之前,必須經過的時間長度。Gets or sets the length of time that must transpire before subsequent ToolTip windows appear as the pointer moves from one control to another.

ShowAlways

取得或設定值,指出即使父控制項為非現用時,是否也會顯示工具提示視窗。Gets or sets a value indicating whether a ToolTip window is displayed, even when its parent control is not active.

Site

取得或設定 ComponentISiteGets or sets the ISite of the Component.

(繼承來源 Component)
StripAmpersands

取得或設定值,以便判斷連字號 (&) 字元的處理方式。Gets or sets a value that determines how ampersand (&) characters are treated.

Tag

取得或設定物件,其中含有與 ToolTip 關聯之程式設計人員提供的資料。Gets or sets the object that contains programmer-supplied data associated with the ToolTip.

ToolTipIcon

取得或設定值,以便定義要顯示在工具提示文字旁的圖示類型。Gets or sets a value that defines the type of icon to be displayed alongside the ToolTip text.

ToolTipTitle

取得或設定工具提示視窗的標題。Gets or sets a title for the ToolTip window.

UseAnimation

取得或設定值,以便判斷顯示工具提示時是否應該使用動畫效果。Gets or sets a value determining whether an animation effect should be used when displaying the ToolTip.

UseFading

取得或設定值,以便判斷顯示工具提示時是否應該使用淡出效果。Gets or sets a value determining whether a fade effect should be used when displaying the ToolTip.

方法

CanExtend(Object)

如果工具提示可以提供擴充項 (Extender) 屬性給指定的目標元件,則會傳回 trueReturns true if the ToolTip can offer an extender property to the specified target component.

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
Dispose()

釋放 Component 所使用的所有資源。Releases all resources used by the Component.

(繼承來源 Component)
Dispose(Boolean)

釋放 Component 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Finalize()

在記憶體回收行程回收 Cursor 之前,釋放 Unmanaged 資源並執行其他清除作業。Releases the unmanaged resources and performs other cleanup operations before the Cursor is reclaimed by the garbage collector.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。Returns an object that represents a service provided by the Component or by its Container.

(繼承來源 Component)
GetToolTip(Control)

擷取與指定控制項相關的工具提示文字。Retrieves the ToolTip text associated with the specified control.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
Hide(IWin32Window)

隱藏指定的工具提示視窗。Hides the specified ToolTip window.

InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
RemoveAll()

移除所有目前與工具提示元件相關聯的工具提示文字。Removes all ToolTip text currently associated with the ToolTip component.

SetToolTip(Control, String)

建立工具提示文字與指定控制項的關聯。Associates ToolTip text with the specified control.

Show(String, IWin32Window)

設定與指定之控制項相關聯的工具提示文字,並以強制回應方式顯示工具提示。Sets the ToolTip text associated with the specified control, and displays the ToolTip modally.

Show(String, IWin32Window, Int32)

設定與指定之控制項相關聯的工具提示文字,然後在指定的持續期限內顯示工具提示。Sets the ToolTip text associated with the specified control, and then displays the ToolTip for the specified duration.

Show(String, IWin32Window, Int32, Int32)

設定與指定之控制項相關聯的工具提示文字,然後在指定的相對位置以強制回應方式顯示工具提示。Sets the ToolTip text associated with the specified control, and then displays the ToolTip modally at the specified relative position.

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

設定與指定之控制項相關聯的工具提示文字,然後在指定的相對位置並於指定的持續期限內顯示工具提示。Sets the ToolTip text associated with the specified control, and then displays the ToolTip for the specified duration at the specified relative position.

Show(String, IWin32Window, Point)

設定與指定之控制項相關聯的工具提示文字,然後在指定的相對位置以強制回應方式顯示工具提示。Sets the ToolTip text associated with the specified control, and then displays the ToolTip modally at the specified relative position.

Show(String, IWin32Window, Point, Int32)

設定與指定之控制項相關聯的工具提示文字,然後在指定的相對位置並於指定的持續期限內顯示工具提示。Sets the ToolTip text associated with the specified control, and then displays the ToolTip for the specified duration at the specified relative position.

StopTimer()

停止隱藏顯示工具提示的計時器。Stops the timer that hides displayed ToolTips.

ToString()

傳回這個控制項的字串 (String) 表示。Returns a string representation for this control.

事件

Disposed

當此元件由 Dispose() 方法的呼叫處置時發生。Occurs when the component is disposed by a call to the Dispose() method.

(繼承來源 Component)
Draw

繪製工具提示而且 OwnerDraw 屬性設定為 trueIsBalloon 屬性設定為 false 時發生。Occurs when the ToolTip is drawn and the OwnerDraw property is set to true and the IsBalloon property is false.

Popup

發生於最初顯示工具提示之前。Occurs before a ToolTip is initially displayed. 此為 ToolTip 類別的預設事件。This is the default event for the ToolTip class.

適用於

另請參閱