HtmlTextWriter HtmlTextWriter HtmlTextWriter HtmlTextWriter Constructors

定義

多載

HtmlTextWriter(TextWriter) HtmlTextWriter(TextWriter) HtmlTextWriter(TextWriter) HtmlTextWriter(TextWriter)

初始化 HtmlTextWriter 類別的新執行個體 (此執行個體使用預設的定位字串)。Initializes a new instance of the HtmlTextWriter class that uses a default tab string.

HtmlTextWriter(TextWriter, String) HtmlTextWriter(TextWriter, String) HtmlTextWriter(TextWriter, String) HtmlTextWriter(TextWriter, String)

使用指定的定位字串字元初始化 HtmlTextWriter 類別的新執行個體。Initializes a new instance of the HtmlTextWriter class with a specified tab string character.

HtmlTextWriter(TextWriter) HtmlTextWriter(TextWriter) HtmlTextWriter(TextWriter) HtmlTextWriter(TextWriter)

初始化 HtmlTextWriter 類別的新執行個體 (此執行個體使用預設的定位字串)。Initializes a new instance of the HtmlTextWriter class that uses a default tab string.

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

呈現標記內容的 TextWriter 執行個體。The TextWriter instance that renders the markup content.

範例

下列程式碼範例HtmlTextWriter(TextWriter)示範如何使用此函式來建立自HtmlTextWriter定義物件StyledLabelHtmlWriter. ,而此MyPage自訂類別(衍生Page自類別)是由用戶端所要求瀏覽器,它會StyledLabelHtmlWriter使用類別,將其內容轉譯為輸出資料流程。The following code example demonstrates how to use the HtmlTextWriter(TextWriter) constructor to create a custom HtmlTextWriter object named StyledLabelHtmlWriter. When the MyPage custom class, which is derived from the Page class, is requested by a client browser, it uses the StyledLabelHtmlWriter class to render its content to the output stream.

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

備註

當需要行的縮排時DefaultTabString ,此函數的多載會使用常數。HtmlTextWriter(TextWriter) HtmlTextWriterThe HtmlTextWriter overload of the HtmlTextWriter(TextWriter) constructor uses the DefaultTabString constant when indentation of a line is necessary. 它會呼叫HtmlTextWriter(TextWriter, String)多載,以初始化新的實例。It calls the HtmlTextWriter(TextWriter, String) overload to initialize the new instance.

另請參閱

HtmlTextWriter(TextWriter, String) HtmlTextWriter(TextWriter, String) HtmlTextWriter(TextWriter, String) HtmlTextWriter(TextWriter, String)

使用指定的定位字串字元初始化 HtmlTextWriter 類別的新執行個體。Initializes a new instance of the HtmlTextWriter class with a specified tab string character.

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

呈現標記內容的 TextWriterThe TextWriter that renders the markup content.

tabString
String String String String

用來呈現行縮排的字串。The string to use to render a line indentation.

範例

下列程式碼範例HtmlTextWriter(TextWriter)示範如何使用此函式來建立自HtmlTextWriter定義物件StyledLabelHtmlWriter. ,而此MyPage自訂類別(衍生Page自類別)是由用戶端所要求瀏覽器,它會StyledLabelHtmlWriter使用類別,將其內容轉譯為輸出資料流程。The following code example demonstrates how to use the HtmlTextWriter(TextWriter) constructor to create a custom HtmlTextWriter object named StyledLabelHtmlWriter. When the MyPage custom class, which is derived from the Page class, is requested by a client browser, it uses the StyledLabelHtmlWriter class to render its content to the output stream.

// 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(TextWriter, String)縮排tabString時,會使用此函數的多載。 HtmlTextWriterThe HtmlTextWriter overload of the HtmlTextWriter(TextWriter, String) constructor uses tabString when indentation of a line is necessary. 它會呼叫TextWriter.TextWriter(IFormatProvider)基底的函式來初始化新的實例。It calls the TextWriter.TextWriter(IFormatProvider) base constructor to initialize the new instance.

另請參閱

適用於