ChtmlTextWriter Constructeurs

Définition

Initialise une nouvelle instance de la classe ChtmlTextWriter.

Surcharges

ChtmlTextWriter(TextWriter)

Initialise une nouvelle instance de la classe ChtmlTextWriter qui utilise la constante DefaultTabString pour mettre des lignes en retrait.

ChtmlTextWriter(TextWriter, String)

Initialise une nouvelle instance de la classe ChtmlTextWriter avec la mise en retrait de ligne spécifiée.

ChtmlTextWriter(TextWriter)

Initialise une nouvelle instance de la classe ChtmlTextWriter qui utilise la constante DefaultTabString pour mettre des lignes en retrait.

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)

Paramètres

writer
TextWriter

TextWriter qui restitue le contenu du balisage.

Exemples

L’exemple de code suivant montre comment créer une classe nommée ChtmlCustomPageAdapter et définit une méthode, CreateCustomChtmlTextWriter, qui crée et retourne une instance de la CustomChtmlTextWriter classe. Le restitue ensuite le CustomChtmlTextWriter contenu cHTML pour les pages sur des appareils avec des navigateurs qui utilisent le balisage cHTML.

Cet exemple de code fait partie d’un exemple plus grand fourni pour la ChtmlTextWriter classe .

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

Remarques

La ChtmlTextWriter classe a deux constructeurs, ce qui est standard pour toutes les classes qui dérivent directement ou indirectement de la HtmlTextWriter classe .

Le ChtmlTextWriter constructeur, qui prend une instance de la TextWriter classe en tant que paramètre, appelle le deuxième constructeur et lui transmet deux valeurs de paramètre :

  • L’TextWriteropérateur

  • Valeur de chaîne spécifiée dans le DefaultTabString champ, qui définit l’espacement de tabulation utilisé par l’enregistreur de texte XHTML.

S’applique à

ChtmlTextWriter(TextWriter, String)

Initialise une nouvelle instance de la classe ChtmlTextWriter avec la mise en retrait de ligne spécifiée.

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)

Paramètres

writer
TextWriter

TextWriter qui restitue le contenu du balisage.

tabString
String

Nombre d'espaces définis dans le Indent.

Exemples

L’exemple de code suivant montre comment créer une classe personnalisée nommée CustomChtmlTextWriter dérivée de la ChtmlTextWriter classe . Il crée deux constructeurs que vous pouvez utiliser pour créer un instance de la classe personnalisée avec le même modèle que toutes les classes qui dérivent, directement ou indirectement, de la HtmlTextWriter classe .

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

Remarques

Le ChtmlTextWriter constructeur, qui prend à la fois une instance de la TextWriter classe et une chaîne en tant que paramètres, appelle le Html32TextWriter constructeur qui prend les mêmes paramètres lorsqu’il crée une instance de la ChtmlTextWriter classe.

S’applique à