如果字体从粗体更改为常规,TreeView 文本将被剪裁
我有一个 WinForms TreeView。 TreeView 表示更详细视图的摘要,我使用的视觉提示之一是使节点的文本变为粗体或常规。 问题是,如果将节点的字体从常规字体更改为粗体,它会剪辑文本,就好像它试图将粗体文本放入常规文本的空间中一样。
稍微浏览一下就会发现,通常的解决方法是将 TreeView 的字体设置为粗体,并有选择地将节点设置为常规字体。
这确实工作得更好,但是一旦我将节点更改为常规,如果我将其变回为粗体,它会再次被剪切。 由于我正在动态更新我的视图,所以我遇到了这个问题。
令人惊讶的是,我在 Stackoverflow 上找不到任何有关此问题的参考资料,所以我想我应该尽自己的一份力量,将其发布到这里。 有谁知道这个问题的更彻底(但最好不要太复杂)的解决方法或解决方案?
我正在使用在 .Net 2.0 上运行的 C# 3,但如果需要,可以使用 .Net 3.5。
[更新]
没有人接受吧?太糟糕了。到目前为止,我自己想到的最好的办法是在字符串的末尾添加一些空格(以给它增长的空间)。这在很多层面上都有味道(尤其是因为它会影响滚动条)。我不想使用第三方控件(或编写我自己的控件),因为这只是我的开发团队的内部应用程序。考虑改变这个比喻,但它很合适。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在 VB.Net 中遇到了同样的问题,解决方案是调用以下代码:
TreeView.BeginUpdate()
'-- 在此处填充您的树节点。
TreeView.EndUpdate()
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()
找到了另一个解决方案:在更改字体后设置文本,而不是在添加具有键和文本属性的节点后更改字体
found another solution: set the text after changing the font instead of changing the font after adding a node with key and text properties
我遇到了同样的问题(C#)。我的解决方案是:一开始将treeView字体设置为粗体,当某些节点不能为粗体时,将字体更改为常规:
I got the same problem (C#). My solution was: at the beginning set the treeView font to bold, and when some nodes must not to be bold, change the font to regular: