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)构造函数创建一个名为MyPage``StyledLabelHtmlWriter.“自定义类(派生自Page该类)由客户端浏览器请求的自定义HtmlTextWriter对象,该类使用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)构造函数创建一个名为MyPage``StyledLabelHtmlWriter.“自定义类(派生自Page该类)由客户端浏览器请求的自定义HtmlTextWriter对象,该类使用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) 基构造函数来初始化新实例。

另请参阅

适用于