Share via


如何:在设计时为 Windows 窗体上的控件设置 ToolTip

可以在代码中或在 Visual Studio 中的 Windows 窗体设计器中设置 ToolTip 字符串。 有关 ToolTip 组件的详细信息,请参阅 ToolTip 组件概述

以编程方式设置 ToolTip

  1. 添加将显示 ToolTip 的控件。

  2. 使用 ToolTip 组件的 SetToolTip 方法。

    ' In this example, Button1 is the control to display the ToolTip.
    ToolTip1.SetToolTip(Button1, "Save changes")
    
    // In this example, button1 is the control to display the ToolTip.
    toolTip1.SetToolTip(button1, "Save changes");
    
    // In this example, button1 is the control to display the ToolTip.
    toolTip1->SetToolTip(button1, "Save changes");
    

在设计器中设置 ToolTip

  1. 在 Visual Studio 中,将 ToolTip 组件添加到窗体。

  2. 选择将显示 ToolTip 的控件,或将它添加到窗体。

  3. 在“属性”窗口中,将“ToolTip1 上的 ToolTip”值设置为适当的文本字符串

以编程方式删除 ToolTip

  1. 使用 ToolTip 组件的 SetToolTip 方法。

    ' In this example, Button1 is the control displaying the ToolTip.
    ToolTip1.SetToolTip(Button1, Nothing)
    
    // In this example, button1 is the control displaying the ToolTip.
    toolTip1.SetToolTip(button1, null);
    
    // In this example, button1 is the control displaying the ToolTip.
    toolTip1->SetToolTip(button1, NULL);
    

在设计器中删除 ToolTip

  1. 在 Visual Studio 中,选择正在显示 ToolTip 的控件。

  2. 在“属性”窗口中,删除“ToolTip1 上的 ToolTip”中的文本

另请参阅