【问题标题】:Tool Tip Text on Mouse Over Particular ListView Sub Item in C# [closed]C# 中鼠标悬停在特定 ListView 子项上的工具提示文本 [关闭]
【发布时间】:2014-05-13 16:17:05
【问题描述】:

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

  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 行显示的是工具提示而不是特定的 ListView 子项?

【问题讨论】:

  • 欢迎来到 Stack Overflow。这不是在这里提出问题的好方法。到目前为止,您是否尝试过任何方法来解决您的问题?首先展示你的努力,这样人们才能展示他们的努力。请阅读FAQHow to Askhelp center 作为开始..
  • 这个问题看起来更像是谷歌搜索而不是 SO 问题
  • 如前所述。欢迎来到 SO,但请展示您的工作。我们都在这里审查你的第一篇文章。 HTH

标签: c# vb.net


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多