Share via


Html32TextWriter.RenderBeforeContent 方法

定義

寫入任何出現在 HTML 項目所包含之內容之前的定位間距或字型資訊。

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

傳回

要在呈現 HTML 項目內容之前寫入的字型資訊或間距,如果沒有這樣的資訊可以呈現,則為 null

範例

下列程式碼範例示範如何覆寫 RenderBeforeContent 方法。 程式碼會檢查項目是否 th 正在轉譯,然後使用 SupportsBold 方法來檢查要求裝置是否可以顯示粗體格式設定。 如果裝置支援粗體格式設定, RenderBeforeContent 此方法會寫入專案的開頭標記 b 。 如果裝置不支援粗體格式設定, RenderBeforeContent 方法會寫入元素的開頭標記 font ,並將 color 屬性設定為紅色的十六進位值。

接下來,每個方法都會檢查項目是否 h4 正在轉譯,然後使用 SupportsItalic 屬性來檢查要求裝置是否可以顯示斜體格式。 如果裝置支援斜體格式設定, RenderBeforeContent 此方法會寫入專案的開頭標記 i 。 如果裝置不支援斜體格式設定, RenderBeforeContent 此方法會寫入元素的開頭標記 font ,並將 color 屬性設定為藍色的十六進位值。

此程式碼範例是針對 類別提供的較大範例的 Html32TextWriter 一部分。

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

適用於

另請參閱