鼠标上的工具提示文本在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子项?
答案 0 :(得分: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);
}