HtmlTextWriter.EnterStyle Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Escreve a etiqueta de abertura de um elemento de marcação que contém atributos que implementam o layout e a formatação de caracteres do estilo especificado.
Sobrecargas
| Name | Description |
|---|---|
| EnterStyle(Style) |
Escreve a etiqueta de abertura de um |
| EnterStyle(Style, HtmlTextWriterTag) |
Escreve a etiqueta de abertura de um elemento de marcação que contém atributos que implementam o layout e a formatação de caracteres do estilo especificado. |
EnterStyle(Style)
Escreve a etiqueta de abertura de um <span> elemento que contém atributos que implementam o layout e a formatação de caracteres do estilo especificado.
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)
Parâmetros
- style
- Style
A Style que especifica o layout e a formatação a começar a aplicar ao bloco de marcação.
Exemplos
O exemplo de código seguinte demonstra como usar uma classe personalizada chamada TextSample, derivada da WebControl classe, que utiliza o EnterStyle método para aplicar um ForeColor estilo a uma cadeia de texto.
O EnterStyle método renderiza o arquivo HTML <span style="color:Navy;">. A ExitStyle chamada ao método fecha o <span> elemento depois de o texto ter sido renderizado.
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
Observações
Use o EnterStyle método para aplicar estilos, como cor de fundo ou largura da borda, a um bloco de marcação.
Os EnterStyle métodos and ExitStyle permitem que um adaptador de dispositivo ou controlo crie marcação que utiliza a formatação de caracteres do estilo especificado. Use o mesmo valor para style no EnterStyle método que usa no método correspondente ExitStyle .
A EnterStyle sobrecarga do EnterStyle(Style) método gera a etiqueta de abertura de um <span> elemento. Este método adiciona então os atributos necessários e os atributos de estilo à etiqueta de abertura do <span> elemento para mostrar as definições especificadas pelo Style objeto. Se quiseres renderizar um elemento de marcação diferente para conter os atributos e os atributos de estilo, usa a EnterStyle(Style, HtmlTextWriterTag) sobrecarga.
Ver também
Aplica-se a
EnterStyle(Style, HtmlTextWriterTag)
Escreve a etiqueta de abertura de um elemento de marcação que contém atributos que implementam o layout e a formatação de caracteres do estilo especificado.
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)
Parâmetros
- style
- Style
A Style que especifica o layout e a formatação a começar a aplicar ao bloco de marcação.
Um HtmlTextWriterTag que especifica a etiqueta de abertura do elemento de marcação que conterá o objeto estilo especificado em style.
Exemplos
O exemplo de código seguinte demonstra como usar uma classe personalizada chamada TextSample, derivada da WebControl classe, que utiliza o EnterStyle método para aplicar um ForeColor estilo a uma cadeia de texto.
O EnterStyle método renderiza o arquivo HTML <span style="color:Navy;">. A ExitStyle chamada ao método fecha o <span> elemento depois de o texto ter sido renderizado.
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
Observações
Use o EnterStyle método para aplicar estilos, como cor de fundo ou largura da borda, a um bloco de marcação.
Os EnterStyle métodos and ExitStyle permitem que um adaptador de dispositivo ou controlo crie marcação que utiliza a formatação de caracteres do estilo especificado. Use o mesmo valor para style no EnterStyle método que usa no método correspondente ExitStyle .
A EnterStyle sobrecarga do EnterStyle(Style, HtmlTextWriterTag) método gera a etiqueta de abertura do elemento especificado pelo tag parâmetro. O EnterStyle(Style, HtmlTextWriterTag) método adiciona então os atributos necessários e os atributos de estilo à etiqueta de abertura do elemento para mostrar as definições especificadas pelo Style objeto. Use a EnterStyle(Style) sobrecarga para renderizar a etiqueta de abertura de um <span> elemento.