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?
Application.EnableVisualStyles();
as the first line of yourMain
method.[STAThread]
attribute individually and by addingApplication.EnableVisualStyles();
the problem solved.