格式化WinForm标签中的文本 [英] Formatting text in WinForm Label
问题描述
是否可以在WinForm标签中格式化某些文本,而不是将文本分解为多个标签?请忽略标签文本中的HTML标签;这只是用来指出我的观点。
例如:
pre $ Dim myLabel As New Label
myLabel.Text =This is< b> bold< / b> text。这是< i>斜体< / i>文字。
这将产生标签中的文字:
这是粗体文字。这是
斜体文本。
因为它是WinForms标签不可能的。标签必须只有一种字体,只有一种尺寸和一张脸。您有几个选项:
$ b $ ol
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.
For example:
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:
This is bold text. This is italicized text.
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:
- Use separate labels
- Create a new Control-derived class that does its own drawing via GDI+ and use that instead of Label; this is probably your best option, as it gives you complete control over how to instruct the control to format its text
- Use a third-party label control that will let you insert HTML snippets (there are a bunch - check CodeProject); this would be someone else's implementation of #2.
这篇关于格式化WinForm标签中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!