question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Bold Property to TreeNode

See original GitHub issue

The native Win32 TreeView control supports the item state flag TVIS_BOLD for making TreeNodes bold. This is not exposed in the Windows Forms TreeNode API.

I would suggest adding a new Property bool Bold { get; set; } to TreeNode, which when set to true, sets the item state flag on the TreeView item.

namespace System.Windows.Forms
{
    public partial class TreeNode
    {
        public bool Bold { get; set; }
    }
}

Describe alternatives you’ve considered The canonical way to do this now by setting the NodeFont to something derived from the original is a bit cumbersome and also has the problem of potentially using the wrong font. The built-in default font may be different from the default font set in the OS.

Setting the state flag manually via P/invoking SendMessage(TVM_SETITEMW ...) works but is difficult to implement and also only works if the TreeNode already has a handle, i.e. it has been added to the TreeView already.

Will this feature affect UI controls? Yes

The new property TreeNode.Bold should be settable via the designer like other TreeNode properties.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jmairboeckcommented, Feb 4, 2020

Also note the hint at the bottom of the docs, mentioning that NodeFont is bugged and will get clipped if the text drawn with NodeFont is larger than what the TreeView font would produce. I wonder if introducing the IsBold flag will have the same problem, since a bold font usually leads to bigger text having a clipping bug present would mean the property would be basically useless.

This is exactly one of the reasons why the TVIS_BOLD flag exists in the first place, to avoid the text clipping problem. See https://devblogs.microsoft.com/oldnewthing/20090406-00/?p=18623

2reactions
RussKiecommented, Feb 5, 2020

A definition for TVIS_BOLD was added in #1742, so we have it in our codebase now.

Bold name does not fit in to the Windows Forms naming convention both at the type level, and at the level of the Windows Forms SDK. Typically a user would think of Bold as being a property of a Font, ~however an individual node does not control Font, instead it is controlled at the TreeView level~ and there is NodeFont property, however it may not work as expected (see below).

In this case I propose we create a property called bool IsBold { get; set; } to control whether a tree node is rendered in bold text or not. This way the property fits well with other IsXxx properties exposed by the TreeNode type.


[UPDATE] applied @weltkante corrections and added a link to more background on the boldness issues

Read more comments on GitHub >

github_iconTop Results From Across the Web

Want to bold few characters of a word get bold in treenode ...
The only workaround for that is to lie about the node text and make it artificially wider by prefixing characters. Which you then...
Read more >
Thread: Treenode text to bold
My app sets a treenodes font property to bold but the width of the item doesn't expand to cope with the obvious increase...
Read more >
Set a node in a Treeview to bold - C# Discussion Boards
I'm trying to set the text of an item of a TreeView to bold. When i set the node font, the node continues...
Read more >
TreeNode.NodeFont Property (System.Windows.Forms)
Gets or sets the font that is used to display the text on the tree node label.
Read more >
Set Tree Node Bold - JD Edwards
This system function sets the text associated with a tree node in bold type face. Parameters. Parent/Child. Input, required. The parent child FC...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found