ChtmlTextWriter Oluşturucular

Tanım

ChtmlTextWriter sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

Name Description
ChtmlTextWriter(TextWriter)

Satırları girintili yapmak için sabitini kullanan sınıfın ChtmlTextWriter yeni bir örneğini DefaultTabString başlatır.

ChtmlTextWriter(TextWriter, String)

Belirtilen satır girintisi ile sınıfının yeni bir örneğini ChtmlTextWriter başlatır.

ChtmlTextWriter(TextWriter)

Satırları girintili yapmak için sabitini kullanan sınıfın ChtmlTextWriter yeni bir örneğini DefaultTabString başlatır.

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)

Parametreler

writer
TextWriter

TextWriter İşaretlemeyi oluşturan içerik.

Örnekler

Aşağıdaki kod örneği, adlı ChtmlCustomPageAdapter bir sınıfın nasıl oluşturulacağını gösterir ve sınıfının bir örneğini CreateCustomChtmlTextWriter oluşturan ve döndüren bir yöntemi CustomChtmlTextWritertanımlar. ardından CustomChtmlTextWriter , cHTML işaretlemesi kullanan tarayıcıları olan cihazlara sayfalar için cHTML içeriği işler.

Bu kod örneği, sınıfı için ChtmlTextWriter sağlanan daha büyük bir örneğin parçasıdır.

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

Açıklamalar

sınıfı, ChtmlTextWriter doğrudan veya dolaylı olarak sınıfından türetilen tüm sınıflar için standart olan iki oluşturucuya HtmlTextWriter sahiptir.

ChtmlTextWriter Sınıfının bir örneğini TextWriter parametre olarak alan oluşturucu, ikinci oluşturucuyu çağırır ve iki parametre değeri geçirir:

  • TextWriter.
  • XHTML metin yazıcısı tarafından kullanılan sekme aralığını tanımlayan alanda belirtilen DefaultTabString dize değeri.

Şunlara uygulanır

ChtmlTextWriter(TextWriter, String)

Belirtilen satır girintisi ile sınıfının yeni bir örneğini ChtmlTextWriter başlatır.

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)

Parametreler

writer
TextWriter

TextWriter İşaretlemeyi oluşturan içerik.

tabString
String

içinde Indenttanımlanan boşluk sayısı.

Örnekler

Aşağıdaki kod örneği, sınıfından CustomChtmlTextWriter türetilen adlı ChtmlTextWriter özel bir sınıfın nasıl oluşturulacağını gösterir. Doğrudan veya dolaylı olarak HtmlTextWriter sınıfından türetilen tüm sınıflarla aynı desene sahip özel sınıfın bir örneğini oluşturmak için kullanabileceğiniz iki oluşturucu oluşturur.

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

Açıklamalar

Hem ChtmlTextWriter sınıfın bir örneğini hem de bir dizeyi TextWriter parametre olarak alan oluşturucu, sınıfın Html32TextWriter bir örneğini oluştururken aynı parametreleri alan oluşturucuyu ChtmlTextWriter çağırır.

Şunlara uygulanır