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경우 기본 새 줄 문자가 사용됩니다.

적용 대상

추가 정보