ToolTip 类

定义

表示一个长方形的小弹出窗口,该窗口在用户将指针悬停在一个控件上时显示有关该控件用途的简短说明。

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 实例将 ShowAlways 属性设置为 , true 使工具提示文本始终显示,而不管窗体是否处于活动状态。 最后,该示例将工具提示文本与窗体上的两个控件(和 ButtonCheckBox)相关联。 代码示例要求示例中定义的方法位于包含Button名为 的控件和CheckBox名为 checkBox1的控件的 中Form,并且该方法是从 的构造函数调用的Formbutton1

// 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移动到显示 Internet 连接状态的控件上时,可以使用 ToolTip 类来显示连接速度和线路质量数据。

ToolTip 可以在任何容器中使用。 若要显式指定容器,请使用 ToolTip(IContainer) 构造函数。 单个 ToolTip 组件通常用于为单个窗体上的多个控件创建工具提示。 创建 后, ToolTip使用对 方法的单独调用 SetToolTip 将工具提示显示文本关联到单个控件。 然后,当用户在控件上移动指针时,将显示工具提示及其文本。 可以为同一控件多次调用 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)

如果工具提示可以向指定的目标组件提供一个扩展程序属性,则返回 true

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(继承自 MarshalByRefObject)
Dispose()

释放由 Component 使用的所有资源。

(继承自 Component)
Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。

Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。

(继承自 Component)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
Finalize()

在垃圾回收器回收 Cursor 之前,释放非托管资源并执行其他清理操作。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetLifetimeService()
已过时.

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 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()

返回此控件的字符串表示形式。

事件

Disposed

在通过调用 Dispose() 方法释放组件时发生。

(继承自 Component)
Draw

当绘制工具提示并将 OwnerDraw 属性设置为 true,以及 IsBalloon 属性为 false 时发生。

Popup

在工具提示最初显示之前发生。 这是 ToolTip 类的默认事件。

适用于

另请参阅