格式化 WinForm 标签中的文本 [英] Formatting text in WinForm Label
本文介绍了格式化 WinForm 标签中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 WinForm 标签中格式化某些文本而不是将文本分成多个标签?请忽略标签文本中的 HTML 标签;它只是用来说明我的观点.
Is it possible to format certain text in a WinForm Label instead of breaking the text into multiple labels? Please disregard the HTML tags within the label's text; it's only used to get my point out.
例如:
Dim myLabel As New Label
myLabel.Text = "This is <b>bold</b> text. This is <i>italicized</i> text."
这会将标签中的文本生成为:
Which would produce the text in the label as:
这是粗体文字.这是斜体文本.
推荐答案
WinForms 标签无法做到这一点.标签必须只有一种字体,一种尺寸和一张脸.您有两种选择:
That's not possible with a WinForms label as it is. The label has to have exactly one font, with exactly one size and one face. You have a couple of options:
- 使用单独的标签
- 创建一个新的 Control 派生类,该类通过 GDI+ 进行自己的绘图并使用它而不是 Label;这可能是您最好的选择,因为它可以让您完全控制如何指示控件格式化其文本
- 使用第三方标签控件,它可以让您插入 HTML 片段(有一堆 - 检查 CodeProject);这将是其他人对 #2 的实现.
这篇关于格式化 WinForm 标签中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文