2

When I add my treeview to a window that I created programtically, the tooltip only shows when the cursor was on a node that had a tooltip as well before it enters the node.

class Program
{
    private static Form window;
    private static TreeView treeView;

    static void Main(string[] args)
    {
        InitialiseComponent();
        window.ShowDialog();
    }

    private static void InitialiseComponent()
    {
        window = new Form();

        treeView = new TreeView(){ShowNodeToolTips = true};

        TreeNode node1 = new TreeNode { Text = "node1", ToolTipText = "node1Tooltip" };
        TreeNode node2 = new TreeNode { Text = "node2", ToolTipText = "node2Tooltip" };
        TreeNode node3 = new TreeNode { Text = "node3" };

        TreeNode node11 = new TreeNode { Text = "node1.1" };
        TreeNode node21 = new TreeNode { Text = "node2.1", ToolTipText = "node2.1Tooltip" };
        TreeNode node22 = new TreeNode { Text = "node2.2"};
        node1.Nodes.Add(node11);
        node2.Nodes.Add(node21);
        node2.Nodes.Add(node22);

        treeView.Nodes.Add(node1);
        treeView.Nodes.Add(node2);
        treeView.Nodes.Add(node3);

        window.Controls.Add(treeView);
    }
}

You need to add windows form as a reference to the project to test this. The hover works properly if you add the treeview to a window that was created with the default windows forms project.

Try to hover over node 2 directly without your cursor being over a node before entering.

Then move your mouse up to node 1 and then back to node 2. the tooltip will show if your cursor was over a node that has a tooltip before.

Why? How can I fix this/make it work?

5
  • 3
    Add Application.EnableVisualStyles(); as the first line of your Main method. Apr 11, 2018 at 14:10
  • 1
    @RezaAghaei Oh wow that worked. Put that as awser. But why dose that work? Apr 11, 2018 at 14:13
  • I don't have any idea about Why. I tried missing things like [STAThread] attribute individually and by adding Application.EnableVisualStyles(); the problem solved. Apr 11, 2018 at 15:21
  • 1
    @RezaAghaei ok well. Should i post the awnser then? Apr 11, 2018 at 15:27
  • Yes, you can post it as answer as it's acceptable for How can I fix this/make it work? Apr 11, 2018 at 16:00

1 Answer 1

4

Add Application.EnableVisualStyles(); as the first line of your Main method. No idea why!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.