Html32TextWriter.RenderBeforeContent Método

Definición

Escribe el espaciado de tabulación o la información de fuente que aparece delante del contenido incluido en un elemento HTML.

protected:
 override System::String ^ RenderBeforeContent();
protected override string RenderBeforeContent ();
override this.RenderBeforeContent : unit -> string
Protected Overrides Function RenderBeforeContent () As String

Devoluciones

String

La información de fuente o el espaciado que se va a escribir antes de representar el contenido del elemento HTML; en caso contrario, si no hay tal información que representar, es null.

Ejemplos

En el ejemplo de código siguiente se muestra cómo invalidar el RenderBeforeContent método . El código comprueba si se representa un th elemento y, a continuación, usa el SupportsBold método para comprobar si el dispositivo solicitante puede mostrar formato en negrita. Si el dispositivo admite formato de negrita, el RenderBeforeContent método escribe la etiqueta de apertura de un b elemento. Si el dispositivo no admite el formato en negrita, el RenderBeforeContent método escribe la etiqueta de apertura de un font elemento con un color atributo establecido en el valor hexadecimal para rojo.

A continuación, cada método comprueba si se representa un h4 elemento y, a continuación, usa la SupportsItalic propiedad para comprobar si el dispositivo solicitante puede mostrar formato cursiva. Si el dispositivo admite formato cursiva, el RenderBeforeContent método escribe la etiqueta de apertura de un i elemento. Si el dispositivo no admite el formato cursiva, el RenderBeforeContent método escribe la etiqueta de apertura de un font elemento con un color atributo establecido en el valor hexadecimal para azul marino.

Este ejemplo de código forma parte de un ejemplo más grande proporcionado para la Html32TextWriter clase .

// Override the RenderBeforeContent method to render
// styles before rendering the content of a <th> element.
protected override string RenderBeforeContent()
{
    // Check the TagKey property. If its value is
    // HtmlTextWriterTag.TH, check the value of the 
    // SupportsBold property. If true, return the
    // opening tag of a <b> element; otherwise, render
    // the opening tag of a <font> element with a color
    // attribute set to the hexadecimal value for red.
    if (TagKey == HtmlTextWriterTag.Th)
    {
        if (SupportsBold)
            return "<b>";
        else
            return "<font color=\"FF0000\">";
    }

    // Check whether the element being rendered
    // is an <H4> element. If it is, check the 
    // value of the SupportsItalic property.
    // If true, render the opening tag of the <i> element
    // prior to the <H4> element's content; otherwise, 
    // render the opening tag of a <font> element 
    // with a color attribute set to the hexadecimal
    // value for navy blue.
    if (TagKey == HtmlTextWriterTag.H4)
    {
        if (SupportsItalic)
            return "<i>";
        else
            return "<font color=\"000080\">";
    }
    // Call the base method.
    return base.RenderBeforeContent();
}
' Override the RenderBeforeContent method to render
' styles before rendering the content of a <th> element.
Protected Overrides Function RenderBeforeContent() As String
    ' Check the TagKey property. If its value is
    ' HtmlTextWriterTag.TH, check the value of the 
    ' SupportsBold property. If true, return the
    ' opening tag of a <b> element; otherwise, render
    ' the opening tag of a <font> element with a color
    ' attribute set to the hexadecimal value for red.
    If TagKey = HtmlTextWriterTag.Th Then
        If (SupportsBold) Then
            Return "<b>"
        Else
            Return "<font color=""FF0000"">"
        End If
    End If

    ' Check whether the element being rendered
    ' is an <H4> element. If it is, check the 
    ' value of the SupportsItalic property.
    ' If true, render the opening tag of the <i> element
    ' prior to the <H4> element's content; otherwise, 
    ' render the opening tag of a <font> element 
    ' with a color attribute set to the hexadecimal
    ' value for navy blue.
    If TagKey = HtmlTextWriterTag.H4 Then
        If (SupportsItalic) Then
            Return "<i>"
        Else
            Return "<font color=""000080"">"
        End If
    End If
    ' Call the base method.
    Return MyBase.RenderBeforeContent()
End Function

Se aplica a

Consulte también