HtmlTextWriter.NewLine Vlastnost

Definice

Získá nebo nastaví ukončovací řetězec řádku používaný objektem 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

Hodnota vlastnosti

String

Ukončovací řetězec řádku používaný aktuálním HtmlTextWriterřetězcem .

Příklady

Následující příklad kódu ukazuje, jak použít vlastní třídu odvozenou z HtmlTextWriter třídy, která přepíše metodu FilterAttributes . Při zavolání přepsání zkontroluje, FilterAttributes jestli zapisovač textu vykresluje nějaké <label> prvky nebo <a> prvky. Pokud ano, metoda určuje, FilterAttributes zda je pro popisek definován atribut stylu. Pokud není definován žádný styl, FilterAttributes metoda nastaví výchozí hodnotu atributu style:color na modrou. Metoda FilterAttributes pak pomocí NewLine vlastnosti vloží konec řádku do značky značek a zapíše všechny ostatní definované atributy.

// 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

Poznámky

Výchozí řetězec ukončování řádku je návrat na začátek řádku následovaný informačním kanálem řádku ("\r\n").

Ukončovací řetězec řádku se zapíše do výstupního datového proudu při každém zavolání jedné z WriteLine metod. Pokud je vlastnost nastavena NewLine na null, použije se výchozí znak nového řádku.

Platí pro

Viz také