想一个单词的大胆几个字符,使用C#得到勇于树节点中的WinForms [英] Want to bold few characters of a word get bold in treenode in winforms using c#

查看:91
本文介绍了想一个单词的大胆几个字符,使用C#得到勇于树节点中的WinForms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有搜索文本框,在树视图进行搜索,我给的结果非常好。但我想那些部分得到大胆,我键入的搜索文本框我的WinForm的

i have "search TextBox" to search in treeview, i give result very well. But i want to get those parts get Bold which i typed in "search TextBox" of my winform.

例:我输入拉姆那么它给*的拉姆的* ESH。

Ex: i Typed Ram then it gives *Ram*esh .

推荐答案

该树节点类不支持,它的文字总是与一种字体得出, TreeView.Font。使文本加粗部分是技术上是可行的,但很难得到正确。您需要启用自定义的TreeView.DrawMode财产和DrawItem事件拉丝,有它的MSDN库文章中一个很好的例子。

The TreeNode class doesn't support that, its Text is always drawn with one font, the TreeView.Font. Making parts of the text bold is technically possible but very hard to get right. You need to enable custom drawing with the TreeView.DrawMode property and DrawItem event, there's a good example of it in the MSDN Library article.

这是容易的部分,硬问题是,该节点是太小了,你在加粗的字体绘制它的部分后,以适合文本。树视图缺少MeasureNodeText事件,它会让你索要足够的空间。造成这种情况的唯一解决方法是撒谎节点文本,并使其人为地前缀字符宽。你那么不DrawItem事件画。很难得到一致的权利,你要考虑一个固定的间距字体来代替。

That's the easy part, the hard problem is that the node is too small to fit the text after you draw parts of it in a bold font. TreeView is missing a "MeasureNodeText" event that would allow you to ask for enough space. The only workaround for that is to lie about the node text and make it artificially wider by prefixing characters. Which you then don't draw in the DrawItem event. Very hard to get consistently right, you'll want to consider a fixed pitch font instead.

我不建议你追求这个,除非该功能对您来说真的很重要。否则这解释了为什么你永远看不到在其他程序中此功能。考虑改变颜色,而不是字体粗细了。仍难胶水拼凑BTW。

I cannot recommend you pursue this unless the feature is really important to you. This otherwise explains why you never see this feature in other programs. Consider changing the color instead of the font weight too. Still hard to glue the pieces together btw.

这篇关于想一个单词的大胆几个字符,使用C#得到勇于树节点中的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆