HtmlTextWriter.NewLine Propiedad

Definición

Obtiene o establece la cadena de terminador de línea utilizada por el objeto 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

Valor de propiedad

String

Cadena de terminador de línea utilizada por el HtmlTextWriter actual.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar una clase personalizada, derivada de la HtmlTextWriter clase , que invalida el FilterAttributes método . Cuando se llama a , la FilterAttributes invalidación comprueba si el escritor de texto representa cualquiera <label> o <a> elementos. Si es así, el FilterAttributes método determina si se define un atributo de estilo para la etiqueta. Si no se define ningún estilo, el FilterAttributes método establece el valor predeterminado para el style:color atributo en azul. A FilterAttributes continuación, el método usa la NewLine propiedad para insertar un salto de línea en la etiqueta de marcado y escribe cualquier otro atributo definido.

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

Comentarios

La cadena de terminador de línea predeterminada es un retorno de carro, seguido de una fuente de línea ("\r\n").

La cadena del terminador de línea se escribe en el flujo de salida cada vez que se llama a uno de los WriteLine métodos. Si la NewLine propiedad se establece nullen , se usa el carácter de línea nuevo predeterminado.

Se aplica a

Consulte también