Need to bold selected node in Windows Forms TreeView control
I have a Windows Forms project using Visual Studio 2010 with c# and .Net 4.,
When selecting a node on a TreeView control I want the text to be bold. Similarly when another node is selected the newly selected node should have its text in bold while the previous node is no longer in bold.
This looks like it would work but in the end I created a custom control inheriting from TreeView and overrode the after select event as follows:
protected override void OnAfterSelect(TreeViewEventArgs e) { if (lastSelectedNode != null) lastSelectedNode.NodeFont = new Font(this.Font, FontStyle.Regular); if (SelectedNode != null) SelectedNode.NodeFont = new Font(this.Font, FontStyle.Bold); SelectedNode.Text = SelectedNode.Text; //Hack due to node not displaying all text correctly lastSelectedNode = SelectedNode; base.OnAfterSelect(e); }
Good advice for drawing but for simple bold I think a custom control was more straight forward. \
.NET Programming
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.
ASKER
Open in new window