Udostępnij za pośrednictwem


ChtmlTextWriter Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy ChtmlTextWriter.

Przeciążenia

ChtmlTextWriter(TextWriter)

Inicjuje ChtmlTextWriter nowe wystąpienie klasy, które używa stałej DefaultTabString do wcięcia wierszy.

ChtmlTextWriter(TextWriter, String)

Inicjuje ChtmlTextWriter nowe wystąpienie klasy z określonym wcięciem wiersza.

ChtmlTextWriter(TextWriter)

Inicjuje ChtmlTextWriter nowe wystąpienie klasy, które używa stałej DefaultTabString do wcięcia wierszy.

public:
 ChtmlTextWriter(System::IO::TextWriter ^ writer);
public ChtmlTextWriter (System.IO.TextWriter writer);
new System.Web.UI.ChtmlTextWriter : System.IO.TextWriter -> System.Web.UI.ChtmlTextWriter
Public Sub New (writer As TextWriter)

Parametry

writer
TextWriter

Element TextWriter renderujący zawartość znaczników.

Przykłady

Poniższy przykład kodu pokazuje, jak utworzyć klasę o nazwie ChtmlCustomPageAdapter i zdefiniować jedną metodę , CreateCustomChtmlTextWriterktóra tworzy i zwraca wystąpienie CustomChtmlTextWriter klasy. Następnie CustomChtmlTextWriter renderuje zawartość cHTML dla stron na urządzeniach z przeglądarkami korzystającymi z znaczników cHTML.

Ten przykład kodu jest częścią większego przykładu podanego ChtmlTextWriter dla klasy.

// Derive from the WebControlAdapter class,
// provide a CreateCustomChtmlTextWriter
// method to attach to the custom writer.
public class ChtmlCustomPageAdapter : WebControlAdapter
{
    protected internal ChtmlTextWriter CreateCustomChtmlTextWriter(
        TextWriter writer)
    {
        return new CustomChtmlTextWriter(writer);
    }
}
' Derive from the WebControlAdapter class,
' provide a CreateCustomChtmlTextWriter
' method to attach the custom writer.
Public Class ChtmlCustomPageAdapter
    Inherits WebControlAdapter

    Protected Friend Function CreateCustomChtmlTextWriter( _
     ByVal writer As TextWriter) As ChtmlTextWriter

        Return New CustomChtmlTextWriter(writer)

    End Function
End Class

Uwagi

Klasa ChtmlTextWriter ma dwa konstruktory, które są standardem dla wszystkich klas, które pochodzą bezpośrednio lub pośrednio z HtmlTextWriter klasy.

Konstruktor ChtmlTextWriter , który przyjmuje wystąpienie TextWriter klasy jako parametr, wywołuje drugi konstruktor i przekazuje dwie wartości parametrów:

  • Element TextWriter.

  • Wartość ciągu określona w DefaultTabString polu, która definiuje odstępy tabulatorów używane przez składnik zapisywania tekstu XHTML.

Dotyczy

ChtmlTextWriter(TextWriter, String)

Inicjuje ChtmlTextWriter nowe wystąpienie klasy z określonym wcięciem wiersza.

public:
 ChtmlTextWriter(System::IO::TextWriter ^ writer, System::String ^ tabString);
public ChtmlTextWriter (System.IO.TextWriter writer, string tabString);
new System.Web.UI.ChtmlTextWriter : System.IO.TextWriter * string -> System.Web.UI.ChtmlTextWriter
Public Sub New (writer As TextWriter, tabString As String)

Parametry

writer
TextWriter

Element TextWriter renderujący zawartość znaczników.

tabString
String

Liczba spacji zdefiniowanych w obiekcie Indent.

Przykłady

W poniższym przykładzie kodu pokazano, jak utworzyć klasę niestandardową o nazwie pochodzącej CustomChtmlTextWriterChtmlTextWriter z klasy. Tworzy dwa konstruktory, których można użyć do utworzenia wystąpienia klasy niestandardowej z tym samym wzorcem co wszystkie klasy, które pochodzą bezpośrednio lub pośrednio z HtmlTextWriter klasy.

// Create a class that derives from the
// ChtmlTextWriter class.
using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls.Adapters;

namespace AspNet.Samples.CS
{
    public class CustomChtmlTextWriter : ChtmlTextWriter
    {
        // Create two constructors for the new
        // text writer.
        public CustomChtmlTextWriter(TextWriter writer) : base(writer, DefaultTabString)
        {
        }

        public CustomChtmlTextWriter(TextWriter writer, String tabString)
            : base(writer, tabString)
        {
        }
        
        // Override the OnAttributeRender method to
        // not render the bgcolor attribute, which is
        // not supported in CHTML.
        protected override bool OnAttributeRender(string name, string value, HtmlTextWriterAttribute key)
        {
            if (String.Equals("bgcolor", name))
            {
                return false;
            }
            
            // Call the ChtmlTextWriter version of the
            // the OnAttributeRender method.
            return base.OnAttributeRender(name, value, key);
        }
    }

    // Derive from the WebControlAdapter class,
    // provide a CreateCustomChtmlTextWriter
    // method to attach to the custom writer.
    public class ChtmlCustomPageAdapter : WebControlAdapter
    {
        protected internal ChtmlTextWriter CreateCustomChtmlTextWriter(
            TextWriter writer)
        {
            return new CustomChtmlTextWriter(writer);
        }
    }
}
' Create a class that derives from the
' ChtmlTextWriter class.
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.WebControls.Adapters

Namespace AspNet.Samples.VB

    Public Class CustomChtmlTextWriter
        Inherits ChtmlTextWriter

        ' Create two constructors for the new
        ' text writer.
        Public Sub New(ByVal writer As TextWriter)
            MyClass.New(writer, DefaultTabString)
        End Sub

        Public Sub New(ByVal writer As TextWriter, ByVal tabString As String)
            MyBase.New(writer, tabString)
        End Sub

        ' Override the OnAttributeRender method to
        ' not render the bgcolor attribute, which is 
        ' not supported in CHTML.
        Protected Overrides Function OnAttributeRender(ByVal name As String, ByVal value As String, ByVal key As HtmlTextWriterAttribute) As Boolean
            If (String.Equals("bgcolor", name)) Then
                Return False
            End If

            ' Call the ChtmlTextWriter version of 
            ' the OnAttributeRender method.
            MyBase.OnAttributeRender(name, value, key)

        End Function
    End Class

    ' Derive from the WebControlAdapter class,
    ' provide a CreateCustomChtmlTextWriter
    ' method to attach the custom writer.
    Public Class ChtmlCustomPageAdapter
        Inherits WebControlAdapter

        Protected Friend Function CreateCustomChtmlTextWriter( _
         ByVal writer As TextWriter) As ChtmlTextWriter

            Return New CustomChtmlTextWriter(writer)

        End Function
    End Class
End Namespace

Uwagi

Konstruktor ChtmlTextWriter , który przyjmuje zarówno wystąpienie TextWriter klasy, jak i ciąg jako parametry, wywołuje Html32TextWriter konstruktor, który przyjmuje te same parametry podczas tworzenia wystąpienia ChtmlTextWriter klasy.

Dotyczy