HtmlTextWriter.NewLine 屬性

定義

取得或設定 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

屬性值

String

目前 HtmlTextWriter 使用的行結束字元字串。

範例

下列程式碼範例示範如何使用衍生自 類別的 HtmlTextWriter 自訂類別覆寫 FilterAttributes 方法。 呼叫時,覆寫會 FilterAttributes 檢查文字寫入器是否呈現任何 <label><a> 專案。 如果是,方法 FilterAttributes 會判斷是否為標籤定義樣式屬性。 如果未定義任何樣式,方法會將 FilterAttributes 屬性的 style:color 預設值設定為藍色。 方法 FilterAttributes 接著會 NewLine 使用 屬性在標記標記中插入分行符號,並寫入任何其他定義的屬性。

// 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 ,則會使用預設的新行字元。

適用於

另請參閱