在 C# 中,将鼠标悬停在特定的 ListView 子项上的工具提示文本



C# 中将鼠标悬停在特定列表视图子项上的工具提示文本。它的代码是什么?

  protected void mouse_over(object sender , Eventargs e)
{
ToolTip tooltp = new ToolTip();
ListViewItem lsvItem = ListView1.GetItemAt(e.Location.X , e.Location.Y);
if (lsvItem .subItems[0].Text = "XXX")
{
tooltp.SetToolTip(ListView1 , "HI");
}
}

但是我面临的问题是整个列表视图行显示工具提示而不是特定的列表视图子项?

将 ListView 的 ShowItemToolTips 属性设置为 true。此外,请使用 ListViewItem.ToolTipText 属性

// 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);
}

最新更新