共用方式為


HtmlTextWriter 建構函式

定義

初始化 HtmlTextWriter 類別的新執行個體。

多載

HtmlTextWriter(TextWriter)

初始化 HtmlTextWriter 類別的新執行個體 (此執行個體使用預設的定位字串)。

HtmlTextWriter(TextWriter, String)

使用指定的定位字串字元初始化 HtmlTextWriter 類別的新執行個體。

HtmlTextWriter(TextWriter)

初始化 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) 構函式來建立名為 的 StyledLabelHtmlWriter 自訂 HtmlTextWriter 物件。 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

備註

需要行縮排時, DefaultTabStringHtmlTextWriter 構函式的多 HtmlTextWriter(TextWriter) 載會使用常數。 它會呼叫 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) 構函式來建立名為 的 StyledLabelHtmlWriter 自訂 HtmlTextWriter 物件。 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) 構函式來初始化新的實例。

另請參閱

適用於