格式化WinForm标签中的文本 [英] Formatting text in WinForm Label

查看:177
本文介绍了格式化WinForm标签中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在WinForm标签中格式化某些文本,而不是将文本分解为多个标签?请忽略标签文本中的HTML标签;这只是用来指出我的观点。



例如:

pre $ Dim myLabel As New Label
myLabel.Text =This is< b> bold< / b> text。这是< i>斜体< / i>文字。

这将产生标签中的文字:


这是粗体文字。这是
斜体文本。


解决方案

因为它是WinForms标签不可能的。标签必须只有一种字体,只有一种尺寸和一张脸。您有几个选项:
$ b $ ol

  • 使用单独的标签
  • 创建一个新的Control派生类通过GDI +进行自己的绘图,并使用它来代替Label;这可能是您最好的选择,因为它可以让您完全控制如何指示控件格式化文本。

  • 使用第三方标签控件,可以插入HTML片段是一堆 - 检查CodeProject);这将是其他人执行#2。


    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:

    1. Use separate labels
    2. 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
    3. 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屋!

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