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を青の属性。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").

たびに 1 つの出力ストリームに書き込まれる行終端記号の文字列のWriteLineメソッドが呼び出されます。The line terminator string is written to the output stream whenever one of the WriteLine methods is called. 場合、NewLineプロパティに設定されてnull既定の新しい改行文字を使用します。If the NewLine property is set to null, the default new line character is used.

適用対象

こちらもご覧ください