HtmlTextWriter 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 HtmlTextWriter 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| HtmlTextWriter(TextWriter) |
初始化一個使用預設 tab 字串的新類別實例 HtmlTextWriter 。 |
| HtmlTextWriter(TextWriter, String) |
初始化一個新的類別實例 HtmlTextWriter ,並使用指定的制表字串字元。 |
HtmlTextWriter(TextWriter)
初始化一個使用預設 tab 字串的新類別實例 HtmlTextWriter 。
public:
HtmlTextWriter(System::IO::TextWriter ^ writer);
public HtmlTextWriter(System.IO.TextWriter writer);
new System.Web.UI.HtmlTextWriter : System.IO.TextWriter -> System.Web.UI.HtmlTextWriter
Public Sub New (writer As TextWriter)
參數
- writer
- TextWriter
就是 TextWriter 渲染標記內容的實例。
範例
以下程式碼範例示範如何使用HtmlTextWriter(TextWriter)建構子建立名為 HtmlTextWriter的自訂StyledLabelHtmlWriter物件。 當 MyPage 客戶端瀏覽器請求從該 Page 類別衍生出的自訂類別時,瀏覽器會利用該 StyledLabelHtmlWriter 類別將其內容渲染到輸出串流中。
// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the StyledLabelHtmlWriter class to render its content.
public ref class MyPage: public Page
{
protected:
virtual HtmlTextWriter^ CreateHtmlTextWriter( TextWriter^ writer ) override
{
return gcnew HtmlStyledLabelWriter( writer );
}
};
// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the HtmlStyledLabelWriter class to render its content.
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class MyPage : Page
{
protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
{
return new HtmlStyledLabelWriter(writer);
}
}
' A custom class that overrides the CreateHtmlTextWriter method.
' This page uses the StyledLabelHtmlWriter to render its content.
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class MyPage
Inherits Page
Protected Overrides Function CreateHtmlTextWriter(ByVal writer As TextWriter) As HtmlTextWriter
Return New HtmlStyledLabelWriter(writer)
End Function 'CreateHtmlTextWriter
End Class
備註
HtmlTextWriter當需要縮排某行時,建構子的HtmlTextWriter(TextWriter)超載會使用常數值DefaultTabString。 它呼叫 HtmlTextWriter(TextWriter, String) 過載來初始化新實例。
另請參閱
適用於
HtmlTextWriter(TextWriter, String)
初始化一個新的類別實例 HtmlTextWriter ,並使用指定的制表字串字元。
public:
HtmlTextWriter(System::IO::TextWriter ^ writer, System::String ^ tabString);
public HtmlTextWriter(System.IO.TextWriter writer, string tabString);
new System.Web.UI.HtmlTextWriter : System.IO.TextWriter * string -> System.Web.UI.HtmlTextWriter
Public Sub New (writer As TextWriter, tabString As String)
參數
- writer
- TextWriter
那 TextWriter 就是渲染標記內容的。
- tabString
- String
用來渲染行條縮排的字串。
範例
以下程式碼範例示範如何使用HtmlTextWriter(TextWriter)建構子建立名為 HtmlTextWriter的自訂StyledLabelHtmlWriter物件。 當 MyPage 客戶端瀏覽器請求從該 Page 類別衍生出的自訂類別時,瀏覽器會利用該 StyledLabelHtmlWriter 類別將其內容渲染到輸出串流中。
// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the StyledLabelHtmlWriter class to render its content.
public ref class MyPage: public Page
{
protected:
virtual HtmlTextWriter^ CreateHtmlTextWriter( TextWriter^ writer ) override
{
return gcnew HtmlStyledLabelWriter( writer );
}
};
// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the HtmlStyledLabelWriter class to render its content.
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class MyPage : Page
{
protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
{
return new HtmlStyledLabelWriter(writer);
}
}
' A custom class that overrides the CreateHtmlTextWriter method.
' This page uses the StyledLabelHtmlWriter to render its content.
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class MyPage
Inherits Page
Protected Overrides Function CreateHtmlTextWriter(ByVal writer As TextWriter) As HtmlTextWriter
Return New HtmlStyledLabelWriter(writer)
End Function 'CreateHtmlTextWriter
End Class
備註
HtmlTextWriter當需要縮排某行時,建構子的超載HtmlTextWriter(TextWriter, String)會使用tabString。 它呼叫 TextWriter.TextWriter(IFormatProvider) 基礎建構子來初始化新實例。