Html32TextWriter.SupportsBold Proprietà

Definizione

Ottiene o imposta un valore Boolean che indica se il dispositivo richiedente supporta testo HTML in grassetto. La proprietà SupportsBold consente di eseguire in modo condizionale il rendering di testo in grassetto nel flusso di output della classe Html32TextWriter.

public:
 property bool SupportsBold { bool get(); void set(bool value); };
public bool SupportsBold { get; set; }
member this.SupportsBold : bool with get, set
Public Property SupportsBold As Boolean

Valore della proprietà

Boolean

true se il dispositivo richiedente supporta il testo in grassetto. In caso contrario, false. Il valore predefinito è true.

Esempio

Nell'esempio di codice seguente viene illustrato come eseguire l'override dei RenderBeforeContent metodi e RenderAfterContent . Ogni override verifica se viene eseguito il rendering di un Label elemento e quindi usa il SupportsBold metodo per verificare se il dispositivo di richiesta può visualizzare la formattazione grassetto. Se il dispositivo supporta la formattazione grassetto, il RenderBeforeContent metodo scrive il tag di apertura di un b elemento e il metodo scrive il RenderAfterContent tag di chiusura. Se il dispositivo non supporta la formattazione grassetto, il metodo scrive il RenderBeforeContent tag di apertura di un Font elemento con un color attributo impostato sul valore esadecimale per rosso e il RenderAfterContent metodo scrive il tag di chiusura.

Questo esempio di codice fa parte di un esempio più grande fornito per la 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

Si applica a

Vedi anche