共用方式為


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

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

備註

ExitStyle方法的多 ExitStyle(Style) 載會在控制項的結束記號之後轉譯專案的結束記號 <span> ,並關閉由對應 EnterStyle 呼叫所開啟的專案。

ExitStyleEnterStyle 方法可讓裝置配接器或控制項使用指定樣式的字元格式來建立開始和結束區塊的標記。 在對應 ExitStyle 方法中使用的 方法中 EnterStyle ,使用相同的值 style

另請參閱

適用於

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

備註

ExitStyle方法的多 ExitStyle(Style, HtmlTextWriterTag) 載會轉譯 控制項結束記號之後所指定的 tag 專案結束記號,並關閉由對應 EnterStyle(Style, HtmlTextWriterTag) 方法呼叫所開啟的專案。

ExitStyleEnterStyle 方法可讓裝置配接器或控制項使用指定樣式的字元格式來建立開始和結束區塊的標記。 在對應 ExitStyle 方法中使用的 方法中 EnterStyle ,使用相同的值 style

另請參閱

適用於