ToolTip ToolTip ToolTip ToolTip Class

定义

表示一个长方形的小弹出窗口,该窗口在用户将指针悬停在一个控件上时显示有关该控件用途的简短说明。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. 然后代码将初始化延迟属性AutoPopDelayInitialDelay,和ReshowDelayThe 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. 最后,该示例将工具提示文本与窗体上的两个控件相关联Button和一个CheckBoxFinally, the example associates ToolTip text with two controls on a form, a Button and a CheckBox. 该代码示例需要在示例中定义的方法是否位于Form,其中包含Button控件命名为button1和一个CheckBox控件命名为checkBox1,并从构造函数中调用该方法FormThe 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. 例如,可以使用ToolTip类,以显示连接速度和质量的数据,当用户将指针拖到PictureBox显示 Internet 连接状态的控件。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.

类别Category 相关联的成员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() ToolTip() ToolTip()

初始化的新实例ToolTip没有指定容器。Initializes a new instance of the ToolTip without a specified container.

ToolTip(IContainer) ToolTip(IContainer) ToolTip(IContainer) ToolTip(IContainer)

初始化的新实例ToolTip类使用指定的容器。Initializes a new instance of the ToolTip class with a specified container.

属性

Active Active Active Active

获取或设置一个值,指示工具提示当前是否活动。Gets or sets a value indicating whether the ToolTip is currently active.

AutomaticDelay AutomaticDelay AutomaticDelay AutomaticDelay

获取或设置工具提示的自动延迟。Gets or sets the automatic delay for the ToolTip.

AutoPopDelay AutoPopDelay AutoPopDelay 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 BackColor BackColor BackColor

获取或设置工具提示的背景色。Gets or sets the background color for the ToolTip.

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(Inherited from Component)
CreateParams CreateParams CreateParams CreateParams

获取用于工具提示窗口的创建参数。Gets the creation parameters for the ToolTip window.

DesignMode DesignMode DesignMode DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events Events Events Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
ForeColor ForeColor ForeColor ForeColor

获取或设置工具提示的前景色。Gets or sets the foreground color for the ToolTip.

InitialDelay InitialDelay InitialDelay InitialDelay

获取或设置工具提示显示之前经过的时间。Gets or sets the time that passes before the ToolTip appears.

IsBalloon IsBalloon IsBalloon IsBalloon

获取或设置一个指示工具提示是否应使用气球状窗口的值。Gets or sets a value indicating whether the ToolTip should use a balloon window.

OwnerDraw OwnerDraw OwnerDraw OwnerDraw

获取或设置一个值,该值指示工具提示是由操作系统绘制还是由你提供的代码绘制。Gets or sets a value indicating whether the ToolTip is drawn by the operating system or by code that you provide.

ReshowDelay ReshowDelay ReshowDelay 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 ShowAlways ShowAlways ShowAlways

获取或设置一个值,该值指示是否显示工具提示窗口,甚至是在其父控件不活动的时候。Gets or sets a value indicating whether a ToolTip window is displayed, even when its parent control is not active.

Site Site Site Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(Inherited from Component)
StripAmpersands StripAmpersands StripAmpersands StripAmpersands

获取或设置一个值,该值确定如何处理 &。Gets or sets a value that determines how ampersand (&) characters are treated.

Tag Tag Tag Tag

获取或设置包含由程序员提供的数据与关联的对象ToolTipGets or sets the object that contains programmer-supplied data associated with the ToolTip.

ToolTipIcon ToolTipIcon ToolTipIcon ToolTipIcon

获取或设置一个值,该值定义要在工具提示文本旁显示的图标的类型。Gets or sets a value that defines the type of icon to be displayed alongside the ToolTip text.

ToolTipTitle ToolTipTitle ToolTipTitle ToolTipTitle

获取或设置工具提示窗口的标题。Gets or sets a title for the ToolTip window.

UseAnimation UseAnimation UseAnimation UseAnimation

获取或设置一个值,该值确定在显示工具提示时是否应使用动画效果。Gets or sets a value determining whether an animation effect should be used when displaying the ToolTip.

UseFading UseFading UseFading UseFading

获取或设置一个值,该值确定在显示工具提示时是否应使用淡入淡出效果。Gets or sets a value determining whether a fade effect should be used when displaying the ToolTip.

方法

CanExtend(Object) CanExtend(Object) CanExtend(Object) CanExtend(Object)

返回true如果工具提示可以向提供一个扩展程序属性指定的目标组件。Returns true if the ToolTip can offer an extender property to the specified target component.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

释放非托管的资源并执行其他清理操作之前Cursor垃圾回收器回收。Releases the unmanaged resources and performs other cleanup operations before the Cursor is reclaimed by the garbage collector.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetToolTip(Control) GetToolTip(Control) GetToolTip(Control) GetToolTip(Control)

检索与指定控件关联的工具提示文本。Retrieves the ToolTip text associated with the specified control.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
Hide(IWin32Window) Hide(IWin32Window) Hide(IWin32Window) Hide(IWin32Window)

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

InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
RemoveAll() RemoveAll() RemoveAll() RemoveAll()

移除当前与工具提示组件关联的所有工具提示文本。Removes all ToolTip text currently associated with the ToolTip component.

SetToolTip(Control, String) SetToolTip(Control, String) SetToolTip(Control, String) SetToolTip(Control, String)

使工具提示文本与指定的控件相关联。Associates ToolTip text with the specified control.

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

设置与指定控件关联的工具提示文本,然后以模式方式显示工具提示。Sets the ToolTip text associated with the specified control, and displays the ToolTip modally.

Show(String, IWin32Window, Int32) Show(String, IWin32Window, Int32) Show(String, IWin32Window, Int32) 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) Show(String, IWin32Window, Int32, Int32) Show(String, IWin32Window, Int32, Int32) 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) Show(String, IWin32Window, Int32, Int32, Int32) Show(String, IWin32Window, Int32, Int32, Int32) 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) Show(String, IWin32Window, Point) Show(String, IWin32Window, Point) 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) Show(String, IWin32Window, Point, Int32) Show(String, IWin32Window, Point, Int32) 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() StopTimer() StopTimer() StopTimer()

停止用于隐藏所显示工具提示的计时器。Stops the timer that hides displayed ToolTips.

ToString() ToString() ToString() ToString()

返回此控件的字符串表示形式。Returns a string representation for this control.

事件

Disposed Disposed Disposed Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
Draw Draw Draw Draw

绘制工具提示时,会发生并OwnerDraw属性设置为trueIsBalloon属性是falseOccurs when the ToolTip is drawn and the OwnerDraw property is set to true and the IsBalloon property is false.

Popup Popup Popup Popup

在工具提示最初显示之前发生。Occurs before a ToolTip is initially displayed. 这是默认事件ToolTip类。This is the default event for the ToolTip class.

适用于

另请参阅