HtmlTextWriter.EnterStyle Metodo

Definizione

Scrive il tag di apertura di un elemento di markup contenente attributi che implementano il layout e la formattazione dei caratteri dello stile specificato.

Overload

EnterStyle(Style)

Scrive il tag di apertura di un elemento <span> contenente attributi che implementano il layout e la formattazione dei caratteri dello stile specificato.

EnterStyle(Style, HtmlTextWriterTag)

Scrive il tag di apertura di un elemento di markup contenente attributi che implementano il layout e la formattazione dei caratteri dello stile specificato.

EnterStyle(Style)

Scrive il tag di apertura di un elemento <span> contenente attributi che implementano il layout e la formattazione dei caratteri dello stile specificato.

public:
 virtual void EnterStyle(System::Web::UI::WebControls::Style ^ style);
public virtual void EnterStyle (System.Web.UI.WebControls.Style style);
abstract member EnterStyle : System.Web.UI.WebControls.Style -> unit
override this.EnterStyle : System.Web.UI.WebControls.Style -> unit
Public Overridable Sub EnterStyle (style As Style)

Parametri

style
Style

Oggetto Style che specifica l'inizio dell'applicazione del layout e della formattazione al blocco di markup.

Esempio

Nell'esempio WebControl di codice seguente viene illustrato come usare una classe personalizzata denominata TextSample, derivata dalla classe, che usa il EnterStyle metodo per applicare uno ForeColor stile a una stringa di testo.

Il EnterStyle metodo esegue il rendering dell'oggetto HTML <span style="color:Navy;">. La ExitStyle chiamata al metodo chiude l'elemento <span> dopo il rendering del testo.

Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Security.Permissions
Imports System.Drawing

' Create a custom class, named TextSample, that renders
' its Text property with styles applied by the
' EnterStyle and ExitStyle methods. 
Namespace AspNet.Samples

    <AspNetHostingPermission(SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public Class TextSample
        Inherits Control

        ' Create an instance of the Style class.
        Private textStyle As Style = New Style()
        Private textMessage As String

        ' Create a Text property.
        Public Property Text() As String
            Get
                Return textMessage
            End Get
            Set(ByVal value As String)
                textMessage = value
            End Set
        End Property


        Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
            ' Set the value of the Text property.
            textMessage = "Hello, World!"

            ' Set the Style object's ForeColor
            ' property to Navy.
            textStyle.ForeColor = Color.Navy

            ' Render the Text property with the style.
            writer.WriteLine("The text property styled: ")
            writer.EnterStyle(textStyle)
            writer.Write(Text)
            writer.ExitStyle(textStyle)

            ' Use the WriteBreak method twice to render
            ' an empty line between the lines of rendered text.
            writer.WriteBreak()
            writer.WriteBreak()

            ' Render the Text property without the style.
            writer.WriteLine("The Text property unstyled: ")
            writer.Write(Text)
        End Sub
    End Class
End Namespace

Commenti

Utilizzare il EnterStyle metodo per applicare stili, ad esempio colore di sfondo o larghezza del bordo, a un blocco di markup.

I EnterStyle metodi e ExitStyle consentono a un adattatore dispositivo o a un controllo di creare markup che usa la formattazione dei caratteri dello stile specificato. Utilizzare lo stesso valore per style nel EnterStyle metodo usato nel metodo corrispondente ExitStyle .

L'overload EnterStyle EnterStyle(Style) del metodo esegue il rendering del tag di apertura di un <span> elemento. Questo metodo aggiunge quindi gli attributi e gli attributi di stile necessari al tag di apertura dell'elemento <span> per visualizzare le impostazioni specificate dall'oggetto Style . Se si vuole eseguire il rendering di un elemento di markup diverso per contenere gli attributi e gli attributi di stile, usare l'overload EnterStyle(Style, HtmlTextWriterTag) .

Vedi anche

Si applica a

EnterStyle(Style, HtmlTextWriterTag)

Scrive il tag di apertura di un elemento di markup contenente attributi che implementano il layout e la formattazione dei caratteri dello stile specificato.

public:
 virtual void EnterStyle(System::Web::UI::WebControls::Style ^ style, System::Web::UI::HtmlTextWriterTag tag);
public virtual void EnterStyle (System.Web.UI.WebControls.Style style, System.Web.UI.HtmlTextWriterTag tag);
abstract member EnterStyle : System.Web.UI.WebControls.Style * System.Web.UI.HtmlTextWriterTag -> unit
override this.EnterStyle : System.Web.UI.WebControls.Style * System.Web.UI.HtmlTextWriterTag -> unit
Public Overridable Sub EnterStyle (style As Style, tag As HtmlTextWriterTag)

Parametri

style
Style

Oggetto Style che specifica l'inizio dell'applicazione del layout e della formattazione al blocco di markup.

tag
HtmlTextWriterTag

Oggetto HtmlTextWriterTag che specifica il tag di apertura dell'elemento di markup che conterrà l'oggetto stile specificato in style.

Esempio

Nell'esempio WebControl di codice seguente viene illustrato come usare una classe personalizzata denominata TextSample, derivata dalla classe, che usa il EnterStyle metodo per applicare uno ForeColor stile a una stringa di testo.

Il EnterStyle metodo esegue il rendering dell'oggetto HTML <span style="color:Navy;">. La ExitStyle chiamata al metodo chiude l'elemento <span> dopo il rendering del testo.

Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Security.Permissions
Imports System.Drawing

' Create a custom class, named TextSample, that renders
' its Text property with styles applied by the
' EnterStyle and ExitStyle methods. 
Namespace AspNet.Samples

    <AspNetHostingPermission(SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public Class TextSample
        Inherits Control

        ' Create an instance of the Style class.
        Private textStyle As Style = New Style()
        Private textMessage As String

        ' Create a Text property.
        Public Property Text() As String
            Get
                Return textMessage
            End Get
            Set(ByVal value As String)
                textMessage = value
            End Set
        End Property


        Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
            ' Set the value of the Text property.
            textMessage = "Hello, World!"

            ' Set the Style object's ForeColor
            ' property to Navy.
            textStyle.ForeColor = Color.Navy

            ' Render the Text property with the style.
            writer.WriteLine("The text property styled: ")
            writer.EnterStyle(textStyle)
            writer.Write(Text)
            writer.ExitStyle(textStyle)

            ' Use the WriteBreak method twice to render
            ' an empty line between the lines of rendered text.
            writer.WriteBreak()
            writer.WriteBreak()

            ' Render the Text property without the style.
            writer.WriteLine("The Text property unstyled: ")
            writer.Write(Text)
        End Sub
    End Class
End Namespace

Commenti

Utilizzare il EnterStyle metodo per applicare stili, ad esempio colore di sfondo o larghezza del bordo, a un blocco di markup.

I EnterStyle metodi e ExitStyle consentono a un adattatore dispositivo o a un controllo di creare markup che usa la formattazione dei caratteri dello stile specificato. Utilizzare lo stesso valore per style nel EnterStyle metodo usato nel metodo corrispondente ExitStyle .

L'overload EnterStyle del metodo esegue il rendering del EnterStyle(Style, HtmlTextWriterTag) tag di apertura dell'elemento specificato dal tag parametro. Il EnterStyle(Style, HtmlTextWriterTag) metodo aggiunge quindi gli attributi e gli attributi di stile necessari al tag di apertura dell'elemento per visualizzare le impostazioni specificate dall'oggetto Style . Usare l'overload per eseguire il rendering del EnterStyle(Style) tag di apertura di un <span> elemento.

Vedi anche

Si applica a