Html32TextWriter.SupportsBold 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个布尔值,该值指示请求设备是否支持粗体 HTML 文本。 使用 SupportsBold 属性按条件向 Html32TextWriter 输出流呈现粗体文本。
public:
property bool SupportsBold { bool get(); void set(bool value); };
public bool SupportsBold { get; set; }
member this.SupportsBold : bool with get, set
Public Property SupportsBold As Boolean
属性值
如果请求设备支持粗体文本,则为 true
;否则为 false
。 默认值为 true
。
示例
下面的代码示例演示如何重写 RenderBeforeContent 和 RenderAfterContent 方法。 每个重写都会检查是否呈现元素 Label
,然后使用 SupportsBold 该方法检查请求设备是否可以显示粗体格式。 如果设备支持加粗格式,该方法 RenderBeforeContent 将写入元素的 b
开始标记,并且 RenderAfterContent 该方法写入其结束标记。 如果设备不支持粗体格式设置,该方法RenderBeforeContent将一个元素的开始标记写入一个Font``color
属性设置为红色的十六进制值,并且RenderAfterContent该方法写入结束标记。
此代码示例是为类提供的大型示例的 Html32TextWriter 一部分。
// Override the RenderBeforeContent method to render
// styles before rendering the content of a <th> element.
protected override string RenderBeforeContent()
{
// Check the TagKey property. If its value is
// HtmlTextWriterTag.TH, check the value of the
// SupportsBold property. If true, return the
// opening tag of a <b> element; otherwise, render
// the opening tag of a <font> element with a color
// attribute set to the hexadecimal value for red.
if (TagKey == HtmlTextWriterTag.Th)
{
if (SupportsBold)
return "<b>";
else
return "<font color=\"FF0000\">";
}
// Check whether the element being rendered
// is an <H4> element. If it is, check the
// value of the SupportsItalic property.
// If true, render the opening tag of the <i> element
// prior to the <H4> element's content; otherwise,
// render the opening tag of a <font> element
// with a color attribute set to the hexadecimal
// value for navy blue.
if (TagKey == HtmlTextWriterTag.H4)
{
if (SupportsItalic)
return "<i>";
else
return "<font color=\"000080\">";
}
// Call the base method.
return base.RenderBeforeContent();
}
' Override the RenderBeforeContent method to render
' styles before rendering the content of a <th> element.
Protected Overrides Function RenderBeforeContent() As String
' Check the TagKey property. If its value is
' HtmlTextWriterTag.TH, check the value of the
' SupportsBold property. If true, return the
' opening tag of a <b> element; otherwise, render
' the opening tag of a <font> element with a color
' attribute set to the hexadecimal value for red.
If TagKey = HtmlTextWriterTag.Th Then
If (SupportsBold) Then
Return "<b>"
Else
Return "<font color=""FF0000"">"
End If
End If
' Check whether the element being rendered
' is an <H4> element. If it is, check the
' value of the SupportsItalic property.
' If true, render the opening tag of the <i> element
' prior to the <H4> element's content; otherwise,
' render the opening tag of a <font> element
' with a color attribute set to the hexadecimal
' value for navy blue.
If TagKey = HtmlTextWriterTag.H4 Then
If (SupportsItalic) Then
Return "<i>"
Else
Return "<font color=""000080"">"
End If
End If
' Call the base method.
Return MyBase.RenderBeforeContent()
End Function