[英]TreeNode mouse hover tooltip not showing up
I am trying to show a tooltip when mouse hovers on a treeview node. 我试图在鼠标悬停在树视图节点上时显示工具提示。 But the tooltip is not showing up.
但工具提示没有显示出来。
This is my code: 这是我的代码:
private void treeView1_MouseHover(object sender, EventArgs e)
{
toolTip1.RemoveAll();
TreeNode selNode = (TreeNode)treeView1.GetNodeAt(Cursor.Position);
if (selNode != null)
{
if (selNode.Tag != null)
{
Product selProduct = selNode.Tag as Product;
if (selProduct != null)
{
toolTip1.SetToolTip(treeView1, selProduct.ProductName + "\n" + selProduct.ProductCategory.ToString());
}
}
}
}
What should I check for? 我应该检查什么?
A much simpler way is to: 一种更简单的方法是:
And you're done. 而且你已经完成了。
looks like the problem is in the 看起来问题就在于
TreeNode selNode = (TreeNode)treeView1.GetNodeAt(Cursor.Position);
line, change it to 行,改为
TreeNode selNode = (TreeNode)treeView1.GetNodeAt(treeView1.PointToClient(Cursor.Position));
and it should work; 它应该工作; I would also recomd to look at the following article: How to add a ToolTip to a TreeNode in Visual C# for detalis on how to add tooltips to the treeview
我还建议您查看以下文章: 如何在Visual C#中向TreeNode添加工具提示以获取有关如何向树视图添加工具提示的详细信息
hope this helps, regards 希望这有帮助,问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.