HtmlTextWriter.ExitStyle 方法

定义

写入标记元素的结束标记以结束指定的布局和字符格式。

重载

名称 说明
ExitStyle(Style)

写入元素的 <span> 结束标记以结束指定的布局和字符格式。

ExitStyle(Style, HtmlTextWriterTag)

写入指定标记元素的结束标记以结束指定的布局和字符格式。

ExitStyle(Style)

写入元素的 <span> 结束标记以结束指定的布局和字符格式。

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

参数

style
Style

指定要关闭的布局和格式的 A Style

示例

下面的代码示例演示如何使用一个名为 TextSample(派生自类)的 WebControl 自定义类,该类使用 EnterStyle 该方法将样式应用于 ForeColor 文本字符串。

该方法 EnterStyle 呈现 HTML <span style="color:Navy;">。 方法 ExitStyle 调用在呈现文本后关闭 <span> 元素。

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

注解

该方法 ExitStyleExitStyle(Style) 重载在控件的结束标记之后呈现元素的 <span> 结束标记,并关闭由相应 EnterStyle 调用打开的元素。

ExitStyleEnterStyle方法允许设备适配器或控件使用指定样式的字符格式创建标记,以开始和结束块。 在相应style方法中使用的方法中EnterStyle使用相同的值ExitStyle

另请参阅

适用于

ExitStyle(Style, HtmlTextWriterTag)

写入指定标记元素的结束标记以结束指定的布局和字符格式。

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

参数

style
Style

一个 Style ,指定要停止应用于输出文本的布局和格式。

tag
HtmlTextWriterTag

一个 HtmlTextWriterTag 指定包含应用指定样式的属性的标记元素的结束标记。 这必须与在相应 EnterStyle 调用中传递的密钥匹配。

示例

下面的代码示例演示如何使用一个名为 TextSample(派生自类)的 WebControl 自定义类,该类使用 EnterStyle 该方法将样式应用于 ForeColor 文本字符串。

该方法 EnterStyle 呈现 HTML <span style="color:Navy;">。 方法 ExitStyle 调用在呈现文本后关闭 <span> 元素。

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

注解

该方法 ExitStyleExitStyle(Style, HtmlTextWriterTag) 重载呈现控件结束标记后指定的 tag 元素的结束标记,并关闭由相应 EnterStyle(Style, HtmlTextWriterTag) 方法调用打开的元素。

ExitStyleEnterStyle方法允许设备适配器或控件使用指定样式的字符格式创建标记,以开始和结束块。 在相应style方法中使用的方法中EnterStyle使用相同的值ExitStyle

另请参阅

适用于