簡體   English   中英

TreeNode鼠標懸停工具提示未顯示

[英]TreeNode mouse hover tooltip not showing up

我試圖在鼠標懸停在樹視圖節點上時顯示工具提示。 但工具提示沒有顯示出來。

這是我的代碼:

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

我應該檢查什么?

一種更簡單的方法是:

  1. 在創建TreeNode時,在TreeNode上設置ToolTipText。
  2. 將TreeView控件的ShowNodeToolTips屬性設置為True。

而且你已經完成了。

看起來問題就在於

TreeNode selNode = (TreeNode)treeView1.GetNodeAt(Cursor.Position);

行,改為

TreeNode selNode = (TreeNode)treeView1.GetNodeAt(treeView1.PointToClient(Cursor.Position));

它應該工作; 我還建議您查看以下文章: 如何在Visual C#中向TreeNode添加工具提示以獲取有關如何向樹視圖添加工具提示的詳細信息

希望這有幫助,問候

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM