Html32TextWriter.RenderBeforeContent Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Escreve qualquer espaçamento de tabulação ou informação de fonte que apareça antes do conteúdo contido num elemento HTML.
protected:
override System::String ^ RenderBeforeContent();
protected override string RenderBeforeContent();
override this.RenderBeforeContent : unit -> string
Protected Overrides Function RenderBeforeContent () As String
Devoluções
A informação da fonte ou espaçamento a escrever antes de renderizar o conteúdo do elemento HTML; caso contrário, se não houver tal informação para render, null.
Exemplos
O exemplo de código seguinte demonstra como sobrescrever o RenderBeforeContent método. O código verifica se um th elemento está a ser renderizado e depois usa o SupportsBold método para verificar se o dispositivo requerente pode mostrar formatação a negrito. Se o dispositivo suportar formatação a negrito, o RenderBeforeContent método escreve a etiqueta de abertura de um b elemento. Se o dispositivo não suportar formatação a negrito, o RenderBeforeContent método escreve a etiqueta de abertura de um font elemento com um color atributo definido para o valor hexadecimal do vermelho.
De seguida, cada método verifica se um h4 elemento está a ser renderizado e depois usa a SupportsItalic propriedade para verificar se o dispositivo solicitante pode mostrar formatação itálica. Se o dispositivo suportar formatação itálica, o RenderBeforeContent método escreve a etiqueta de abertura de um i elemento. Se o dispositivo não suportar formatação itálica, o RenderBeforeContent método escreve a etiqueta de abertura de um font elemento com um color atributo definido para o valor hexadecimal do azul-marinho.
Este exemplo de código faz parte de um exemplo maior fornecido para a Html32TextWriter classe.
// 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