ToolTip 类

定义

表示一个长方形的小弹出窗口,该窗口在用户将指针悬停在一个控件上时显示有关该控件用途的简短说明。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 , 以使 ToolTip 文本始终显示, 而不管窗体是否处于活动状态。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两个控件 ( CheckBox和) 相关联。Finally, the example associates ToolTip text with two controls on a form, a Button and a CheckBox. 此代码示例要求在示例中定义的Form方法位于Button包含名为button1的控件和CheckBox名为checkBox1的控件, 并且该方法是从构造函数中调用的。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. 例如, 当用户将指针移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. true除非将ShowAlways属性设置为, 否则在其容器处于非活动状态时, 不会显示工具提示。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

如果要禁用所有 ToolTip 文本, 使其无法在应用程序中显示, 则可以使用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, 可以OwnerDrawDraw属性设置为true并处理事件。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.

类实现接口, 该接口CanExtend具有一个方法。 System.ComponentModel.IExtenderProvider ToolTipTitleThe 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

获取 IContainer,它包含 ComponentGets 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)

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

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。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 占用的非托管资源,还可以另外再释放托管资源。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 之前,释放非托管资源并执行其他清理操作。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()

检索控制此实例的生存期策略的当前生存期服务对象。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()

返回此控件的字符串表示形式。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 属性设置为 true,以及 IsBalloon 属性为 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.

适用于

另请参阅