HtmlTextWriter.NewLine 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置 HtmlTextWriter 对象使用的行结束符字符串。
public:
virtual property System::String ^ NewLine { System::String ^ get(); void set(System::String ^ value); };
public override string NewLine { get; set; }
member this.NewLine : string with get, set
Public Overrides Property NewLine As String
属性值
由当前 HtmlTextWriter 使用的行结束符字符串。
示例
下面的代码示例演示如何使用从 HtmlTextWriter 类派生的自定义类替代 FilterAttributes 该方法。 调用时,重写将 FilterAttributes 检查文本编写器是否呈现任何 <label>
元素或 <a>
元素。 如果是,此方法 FilterAttributes 确定是否为标签定义了样式属性。 如果未定义样式,该方法 FilterAttributes 会将 style:color
属性的默认值设置为蓝色。 然后,NewLine该方法FilterAttributes使用属性在标记标记中插入换行符,并写入任何其他定义的属性。
// Override the FilterAttributes method to check whether
// <label> and <anchor> elements contain specific attributes.
virtual void FilterAttributes() override
{
// If the <label> element is rendered and a style
// attribute is not defined, add a style attribute
// and set its value to blue.
if ( TagKey == HtmlTextWriterTag::Label )
{
if ( !IsAttributeDefined( HtmlTextWriterAttribute::Style ) )
{
AddAttribute( "style", EncodeAttributeValue( "color:blue", true ) );
Write( NewLine );
Indent = 3;
OutputTabs();
}
}
// If an <anchor> element is rendered and an href
// attribute has not been defined, call the AddAttribute
// method to add an href attribute
// and set it to http://www.cohowinery.com.
// Use the EncodeUrl method to convert any spaces to %20.
if ( TagKey == HtmlTextWriterTag::A )
{
if ( !IsAttributeDefined( HtmlTextWriterAttribute::Href ) )
{
AddAttribute( "href", EncodeUrl( "http://www.cohowinery.com" ) );
}
}
// Call the FilterAttributes method of the base class.
__super::FilterAttributes();
}
// Override the FilterAttributes method to check whether
// <label> and <anchor> elements contain specific attributes.
protected override void FilterAttributes()
{
// If the <label> element is rendered and a style
// attribute is not defined, add a style attribute
// and set its value to blue.
if (TagKey == HtmlTextWriterTag.Label)
{
if (!IsAttributeDefined(HtmlTextWriterAttribute.Style))
{
AddAttribute("style", EncodeAttributeValue("color:blue", true));
Write(NewLine);
Indent = 3;
OutputTabs();
}
}
// If an <anchor> element is rendered and an href
// attribute has not been defined, call the AddAttribute
// method to add an href attribute
// and set it to http://www.cohowinery.com.
// Use the EncodeUrl method to convert any spaces to %20.
if (TagKey == HtmlTextWriterTag.A)
{
if (!IsAttributeDefined(HtmlTextWriterAttribute.Href))
{
AddAttribute("href", EncodeUrl("http://www.cohowinery.com"));
}
}
// Call the FilterAttributes method of the base class.
base.FilterAttributes();
}
' Override the FilterAttributes method to check whether
' <label> and <anchor> elements contain specific attributes.
Protected Overrides Sub FilterAttributes()
' If the <label> element is rendered and a style
' attribute is not defined, add a style attribute
' and set its value to blue.
If TagKey = HtmlTextWriterTag.Label Then
If Not IsAttributeDefined(HtmlTextWriterAttribute.Style) Then
AddAttribute("style", EncodeAttributeValue("color:blue", True))
Write(NewLine)
Indent = 3
OutputTabs()
End If
End If
' If an <anchor> element is rendered and an href
' attribute has not been defined, call the AddAttribute
' method to add an href attribute
' and set it to http://www.cohowinery.com.
' Use the EncodeUrl method to convert any spaces to %20.
If TagKey = HtmlTextWriterTag.A Then
If Not IsAttributeDefined(HtmlTextWriterAttribute.Href) Then
AddAttribute("href", EncodeUrl("http://www.cohowinery.com"))
End If
End If
' Call the FilterAttributes method of the base class.
MyBase.FilterAttributes()
End Sub
注解
默认行终止符字符串是回车符,后跟换行符 (“\r\n”) 。
每当调用其中一个 WriteLine 方法时,行终止符字符串将写入输出流。 NewLine如果该属性设置为 null
,则使用默认的新行字符。