Html32TextWriter 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將一系列 HTML 3.2 特定字元和文字寫入 ASP.NET 伺服器控制項的輸出資料流。 Html32TextWriter 類別會提供格式化功能,讓 ASP.NET 伺服器控制項可在向用戶端呈現 HTML 3.2 內容時加以使用。
public ref class Html32TextWriter : System::Web::UI::HtmlTextWriter
public class Html32TextWriter : System.Web.UI.HtmlTextWriter
type Html32TextWriter = class
inherit HtmlTextWriter
Public Class Html32TextWriter
Inherits HtmlTextWriter
- 繼承
- 衍生
範例
下列程式碼範例示範如何使用衍生自 類別的 Html32TextWriter 類別,名為 CustomHtml32TextWriter
。 CustomHtml32TextWriter
會建立兩個建構函式,遵循 類別所 HtmlTextWriter 建立的模式,並覆寫 RenderBeforeContent 、 RenderAfterContent 、 RenderBeforeTag 和 RenderAfterTag 方法。
using System.IO;
using System.Web.UI;
namespace Examples.AspNet
{
public class CustomHtml32TextWriter : Html32TextWriter
{
// Create a constructor for the class
// that takes a TextWriter as a parameter.
public CustomHtml32TextWriter(TextWriter writer)
: this(writer, DefaultTabString)
{
}
// Create a constructor for the class that takes
// a TextWriter and a string as parameters.
public CustomHtml32TextWriter(TextWriter writer, String tabString)
: base(writer, tabString)
{
}
// 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 RenderAfterContent method to close
// styles opened during the call to the RenderBeforeContent
// method.
protected override string RenderAfterContent()
{
// Check whether the element being rendered is a <th> element.
// If so, and the requesting device supports bold formatting,
// render the closing tag of the <b> element. If not,
// render the closing tag of the <font> element.
if (TagKey == HtmlTextWriterTag.Th)
{
if (SupportsBold)
return "</b>";
else
return "</font>";
}
// Check whether the element being rendered is an <H4>.
// element. If so, and the requesting device supports italic
// formatting, render the closing tag of the <i> element.
// If not, render the closing tag of the <font> element.
if (TagKey == HtmlTextWriterTag.H4)
{
if (SupportsItalic)
return "</i>";
else
return "</font>";
}
// Call the base method
return base.RenderAfterContent();
}
// Override the RenderBeforeTag method to render the
// opening tag of a <small> element to modify the text size of
// any <a> elements that this writer encounters.
protected override string RenderBeforeTag()
{
// Check whether the element being rendered is an
// <a> element. If so, render the opening tag
// of the <small> element; otherwise, call the base method.
if (TagKey == HtmlTextWriterTag.A)
return "<small>";
return base.RenderBeforeTag();
}
// Override the RenderAfterTag method to render
// close any elements opened in the RenderBeforeTag
// method call.
protected override string RenderAfterTag()
{
// Check whether the element being rendered is an
// <a> element. If so, render the closing tag of the
// <small> element; otherwise, call the base method.
if (TagKey == HtmlTextWriterTag.A)
return "</small>";
return base.RenderAfterTag();
}
}
}
' Create a custom HtmlTextWriter class that overrides
' the RenderBeforeContent and RenderAfterContent methods.
Imports System.IO
Imports System.Web.UI
Namespace Examples.AspNet
Public Class CustomHtml32TextWriter
Inherits Html32TextWriter
' Create a constructor for the class
' that takes a TextWriter as a parameter.
Public Sub New(ByVal writer As TextWriter)
Me.New(writer, DefaultTabString)
End Sub
' Create a constructor for the class that takes
' a TextWriter and a string as parameters.
Public Sub New(ByVal writer As TextWriter, ByVal tabString As String)
MyBase.New(writer, tabString)
End Sub
' 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
' Override the RenderAfterContent method to close
' styles opened during the call to the RenderBeforeContent
' method.
Protected Overrides Function RenderAfterContent() As String
' Check whether the element being rendered is a <th> element.
' If so, and the requesting device supports bold formatting,
' render the closing tag of the <b> element. If not,
' render the closing tag of the <font> element.
If TagKey = HtmlTextWriterTag.Th Then
If SupportsBold Then
Return "</b>"
Else
Return "</font>"
End If
End If
' Check whether the element being rendered is an <H4>.
' element. If so, and the requesting device supports italic
' formatting, render the closing tag of the <i> element.
' If not, render the closing tag of the <font> element.
If TagKey = HtmlTextWriterTag.H4 Then
If (SupportsItalic) Then
Return "</i>"
Else
Return "</font>"
End If
End If
' Call the base method.
Return MyBase.RenderAfterContent()
End Function
' Override the RenderBeforeTag method to render the
' opening tag of a <small> element to modify the text size of
' any <a> elements that this writer encounters.
Protected Overrides Function RenderBeforeTag() As String
' Check whether the element being rendered is an
' <a> element. If so, render the opening tag
' of the <small> element; otherwise, call the base method.
If TagKey = HtmlTextWriterTag.A Then
Return "<small>"
End If
Return MyBase.RenderBeforeTag()
End Function
' Override the RenderAfterTag method to render
' close any elements opened in the RenderBeforeTag
' method call.
Protected Overrides Function RenderAfterTag() As String
' Check whether the element being rendered is an
' <a> element. If so, render the closing tag of the
' <small> element; otherwise, call the base method.
If TagKey = HtmlTextWriterTag.A Then
Return "</small>"
End If
Return MyBase.RenderAfterTag()
End Function
End Class
End Namespace
備註
類別 Html32TextWriter 是 類別的 HtmlTextWriter 替代方案。 它會將 HTML 4.0 樣式屬性轉換成相等的 HTML 3.2 標記和屬性。 它會使用 HTML 表格來標準化屬性的傳播,例如色彩和字型。 ASP.NET 透過檢查 TagWriter 類別的 HttpBrowserCapabilities 屬性,自動將此類別用於 HTML 3.2 和更早版本的瀏覽器。 除非您建立以使用 HTML 3.2 標記之裝置為目標的自訂頁面或控制項配接器,否則您不需要明確建立 類別的 Html32TextWriter 實例。
如需自訂頁面和控制項轉譯的詳細資訊,請參閱逐步解 說:開發和使用自訂 Web 服務器控制項。
建構函式
Html32TextWriter(TextWriter) |
當提出要求的瀏覽器需要行縮排時,使用在 Html32TextWriter 欄位內指定的行縮排,初始化 DefaultTabString 類別的新執行個體。 |
Html32TextWriter(TextWriter, String) |
使用指定的行縮排,初始化 Html32TextWriter 類別的新執行個體。 |
欄位
CoreNewLine |
儲存這個 |
DefaultTabString |
表示單一定位字元。 (繼承來源 HtmlTextWriter) |
DoubleQuoteChar |
表示引號 (") 字元。 (繼承來源 HtmlTextWriter) |
EndTagLeftChars |
表示標記項目結尾標記的左角括弧和斜線符號 (</)。 (繼承來源 HtmlTextWriter) |
EqualsChar |
表示等號 ( |
EqualsDoubleQuoteString |
表示組成字串 (=") 的等號 (=) 和雙引號 (")。 (繼承來源 HtmlTextWriter) |
SelfClosingChars |
表示空格以及標記的自行結尾斜線符號 (/)。 (繼承來源 HtmlTextWriter) |
SelfClosingTagEnd |
表示自我結尾標記項目的結尾斜線符號和右角括弧 (/>)。 (繼承來源 HtmlTextWriter) |
SemicolonChar |
表示分號 (;)。 (繼承來源 HtmlTextWriter) |
SingleQuoteChar |
表示所有格符號 (')。 (繼承來源 HtmlTextWriter) |
SlashChar |
表示斜線符號 (/)。 (繼承來源 HtmlTextWriter) |
SpaceChar |
表示空格 ( ) 字元。 (繼承來源 HtmlTextWriter) |
StyleEqualsChar |
表示樣式等號 ( |
TagLeftChar |
表示標記的開頭角括弧 (<)。 (繼承來源 HtmlTextWriter) |
TagRightChar |
表示標記的結尾角括弧 (>)。 (繼承來源 HtmlTextWriter) |
屬性
Encoding |
取得 HtmlTextWriter 物件用來將內容寫入網頁的編碼。 (繼承來源 HtmlTextWriter) |
FontStack |
取得要呈現之 HTML 的字型資訊集合。 |
FormatProvider |
取得控制格式設定的物件。 (繼承來源 TextWriter) |
Indent |
取得或設定定位點位置的數目,此為標記的每一行開頭要縮排的數目。 (繼承來源 HtmlTextWriter) |
InnerWriter |
取得或設定寫入標記項目內部內容的文字寫入器。 (繼承來源 HtmlTextWriter) |
NewLine |
取得或設定 HtmlTextWriter 物件所用的行結束字元字串。 (繼承來源 HtmlTextWriter) |
ShouldPerformDivTableSubstitution |
取得或設定布林值,指出是否將 |
SupportsBold |
取得或設定布林值,指出提出要求的裝置是否支援粗體 HTML 文字。 請使用 SupportsBold 屬性,條件式地呈現粗體文字至 Html32TextWriter 輸出資料流。 |
SupportsItalic |
取得或設定布林值,指出提出要求的裝置是否支援斜體 HTML 文字。 請使用 SupportsItalic 屬性,條件式地呈現斜體文字至 Html32TextWriter 輸出資料流。 |
TagKey |
取得或設定指定標記項目的 HtmlTextWriterTag 值。 (繼承來源 HtmlTextWriter) |
TagName |
取得或設定所呈現的標記項目的標記名稱。 (繼承來源 HtmlTextWriter) |
方法
明確介面實作
IDisposable.Dispose() |
如需這個成員的說明,請參閱 Dispose()。 (繼承來源 TextWriter) |
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應