ListViewItem.ToolTipText Property

Definition

获取或设置当鼠标指针停留在 ListViewItem 上时显示的文本。Gets or sets the text shown when the mouse pointer rests on the ListViewItem.

public:
 property System::String ^ ToolTipText { System::String ^ get(); void set(System::String ^ value); };
public string ToolTipText { get; set; }
member this.ToolTipText : string with get, set
Public Property ToolTipText As String

Property Value

String

当鼠标指针停留在 ListViewItem 上时显示的文本。The text shown when the mouse pointer rests on the ListViewItem.

Examples

下面的代码示例演示如何使用 "ListView.ShowItemToolTips" 和 "ToolTipText" 属性。The following code example demonstrates how to use the ListView.ShowItemToolTips and ToolTipText properties. 若要运行此示例,请将代码粘贴到 Windows 窗体中,并从窗体的构造函数或 Load 事件处理方法调用 InitializeItemsWithToolTipsTo run this example, paste the code into a Windows Form and call InitializeItemsWithToolTips from the form's constructor or Load event-handling method.


// Declare the ListView.
private ListView ListViewWithToolTips;
private void InitializeItemsWithToolTips()
{

    // Construct and set the View property of the ListView.
    ListViewWithToolTips = new ListView();
    ListViewWithToolTips.Width = 200;
    ListViewWithToolTips.View = View.List;

    // Show item tooltips.
    ListViewWithToolTips.ShowItemToolTips = true;
    
    // Create items with a tooltip.
    ListViewItem item1WithToolTip = new ListViewItem("Item with a tooltip");
    item1WithToolTip.ToolTipText = "This is the item tooltip.";
    ListViewItem item2WithToolTip = new ListViewItem("Second item with a tooltip");
    item2WithToolTip.ToolTipText = "A different tooltip for this item.";

    // Create an item without a tooltip.
    ListViewItem itemWithoutToolTip = new ListViewItem("Item without tooltip.");

    // Add the items to the ListView.
    ListViewWithToolTips.Items.AddRange(new ListViewItem[]{item1WithToolTip, 
        item2WithToolTip, itemWithoutToolTip} );

    // Add the ListView to the form.
    this.Controls.Add(ListViewWithToolTips);
    this.Controls.Add(button1);
}
' Declare the ListView.
Private ListViewWithToolTips As ListView

Private Sub InitializeItemsWithToolTips() 
    
    ' Construct and set the View property of the ListView.
    ListViewWithToolTips = New ListView()
    ListViewWithToolTips.Width = 200
    ListViewWithToolTips.View = View.List
    
    ' Show item tooltips.
    ListViewWithToolTips.ShowItemToolTips = True
    
    ' Create items with a tooltip.
    Dim item1WithToolTip As New ListViewItem("Item with a tooltip")
    item1WithToolTip.ToolTipText = "This is the item tooltip."
    Dim item2WithToolTip As New ListViewItem("Second item with a tooltip")
    item2WithToolTip.ToolTipText = "A different tooltip for this item."
    
    ' Create an item without a tooltip.
    Dim itemWithoutToolTip As New ListViewItem("Item without tooltip.")
    
    ' Add the items to the ListView.
    ListViewWithToolTips.Items.AddRange(New ListViewItem() _
        {item1WithToolTip, item2WithToolTip, itemWithoutToolTip})
    
    ' Add the ListView to the form.
    Me.Controls.Add(ListViewWithToolTips)
    Me.Controls.Add(button1)

End Sub

Remarks

如果 ListViewItem 及其包含的 ListView 均设置了 Tooltip,则仅显示 ListViewItem 的工具提示。If both the ListViewItem and its containing ListView have ToolTips set, only the ToolTip for the ListViewItem will be shown.

Applies to