Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TreeView text clipped if font changed from bold to regular

I have a WinForms TreeView. The TreeView represents a summary of more detailed views and one of the visual cues I am using is to make a node's text bold or regular. The trouble is, if you change a node's font from regular to bold it clips the text as if it is trying to fit the bold text in the space for the regular text.

A bit of browsing around shows that the usual workaround is to set the TreeView's font to the bold font, and selectively set nodes to regular.

This does work better, but once I have changed a node to regular, if I then change it back to bold it gets clipped again. Since I'm dynamically updating my view I'm hitting this problem.

Surprisingly I couldn't find any references to this issue on Stackoverflow, so thought I'd do my bit and float it here now. Does anyone know of a more thorough (but preferably not too overcomplex) workaround or solution to this issue?

I'm using C# 3 running on .Net 2.0, but can use .Net 3.5 if necessary.

[update]

No takers eh? That sucks. The best I have come up with myself so far is to add a load of spaces to the end of the string (to give it room to grow). That smells on so many levels (not least because it affects the scrollbars). I don't want to have to go for a third party control (or write my own) because this is just for an internal app for my dev team. Considering changing the metaphor, but it's a good fit.

like image 597
philsquared Avatar asked Dec 14 '22 00:12

philsquared


2 Answers

I ran into the same problem with VB.Net and the solution was to call the following:

TreeView.BeginUpdate() '-- Poupulate your tree nodes here. TreeView.EndUpdate()

like image 51
Edhy Avatar answered Dec 22 '22 01:12

Edhy


found another solution: set the text after changing the font instead of changing the font after adding a node with key and text properties

like image 23
Coder22 Avatar answered Dec 22 '22 01:12

Coder22