[英]Why label control does not render DIV as HTML (AllowHtmlString=true)
I want to center some of the strings. 我想中心的某些字符串。
I saw it. 我看到了。
https://documentation.devexpress.com/WindowsForms/9536/Controls-and-Libraries/Editors-and-Simple-Controls/Simple-Editors/Examples/How-to-Format-Text-in-LabelControl-Using-HTML-Tags https://documentation.devexpress.com/WindowsForms/9536/Controls-and-Libraries/Editors-and-Simple-Controls/Simple-Editors/Examples/How-to-Format-Text-in-LabelControl-Using-HTML-标签
So, I wrote this code. 所以,我写了这段代码。
labelControl1.Text = "<div style=\"text-align:center;\">center</div><br>" +
"<size=14>Size = 14<br>" +
"Bold <i>Italic</i> <u>Underline</u><br>" +
"<color=255, 0, 0>Sample Text</color></size>";
labelControl1.AllowHtmlString = true;
labelControl1.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
labelControl1.Appearance.Options.UseTextOptions = true;
labelControl1.AutoSizeMode = LabelAutoSizeMode.Vertical;
But, it didn't work. 但是,它没有用。
What is the problem with it? 有什么问题吗?
According to the documentation , only specific HTML tags are supported, and div is not in the list. 根据文档 ,仅支持特定的HTML标记,并且div不在列表中。
Depending on your requirements, you might split the text into two labels, one centered (AutoSize=False, TextAlign=MiddleCenter) and one with HTML. 根据您的要求,您可以将文本分为两个标签,一个标签居中(AutoSize = False,TextAlign = MiddleCenter),另一个标签为HTML。
According to HTML Text Formatting documentation , LabelControl.AllowHtmlString
property support these tags and "pseudotags" (tags which not exist in current HTML standard but can be used for rendering purpose in label control): 根据HTML文本格式设置文档 , LabelControl.AllowHtmlString
属性支持以下标记和“伪标记”(当前HTML标准中不存在但可用于标记控件中呈现的标记):
Normal HTML tags 普通HTML标签
<b>
- bold text <b>
-粗体字
<i>
- italic text <i>
-斜体文字
<s>
- strikethrough <s>
-删除线
<u>
- underline <u>
-下划线
<br>
(current HTML equivalent is <br />
) <br>
(当前HTML等效为<br />
)
Pseudotags 伪标签
<color>
(equivalent to CSS color
) <color>
(等同于CSS color
)
<backcolor>
(equivalent to CSS background-color
) <backcolor>
(等效于CSS background-color
)
<size>
(equivalent to CSS font-size
) <size>
(相当于CSS font-size
)
<image=value>
(equivalent to HTML <img src="value">
) <image=value>
(等同于HTML <img src="value">
)
<href=url>
(equivalent to HTML <a href="url">
) <href=url>
(等同于HTML <a href="url">
)
<nbsp>
(equivalent to HTML
) <nbsp>
(等同于HTML
)
The HTML <div>
tag is not included in supported tags mentioned above, hence it will rendered as standard text instead. HTML <div>
标记未包含在上述支持的标记中,因此它将呈现为标准文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.