HtmlTextWriter.NewLine HtmlTextWriter.NewLine HtmlTextWriter.NewLine HtmlTextWriter.NewLine Property

定義

取得或設定 HtmlTextWriter 物件所用的行結束字元字串。Gets or sets the line terminator string used by the HtmlTextWriter object.

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 使用的行結束字元字串。The line terminator string used by the current HtmlTextWriter.

範例

下列程式碼範例示範如何使用衍生HtmlTextWriter自類別的自訂類別來FilterAttributes覆寫方法。The following code example shows how to use a custom class, derived from the HtmlTextWriter class, that overrides the FilterAttributes method. 當呼叫時, FilterAttributes覆寫會檢查文字寫入器是否<label>呈現<a>任何或元素。When called, the FilterAttributes override checks whether the text writer renders any <label> or <a> elements. 若是如此,此FilterAttributes方法會決定是否為標籤定義樣式屬性。If so, the FilterAttributes method determines whether a style attribute is defined for the label. 如果未定義任何樣式,則FilterAttributes方法會將style:color屬性的預設值設定為 blue。If no style is defined, the FilterAttributes method sets the default value for the style:color attribute to blue. 然後FilterAttributes ,方法會NewLine使用屬性,在標記標記中插入分行符號,並寫入任何其他已定義的屬性。The FilterAttributes method then uses the NewLine property to insert a line break in the markup tag and writes any other defined attributes.

// 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")。The default line terminator string is a carriage return, followed by a line feed ("\r\n").

每當呼叫其中一個WriteLine方法時,行結束字元字串就會寫入至輸出資料流程。The line terminator string is written to the output stream whenever one of the WriteLine methods is called. 如果屬性設定為null,則會使用預設換行字元。 NewLineIf the NewLine property is set to null, the default new line character is used.

適用於

另請參閱