HtmlTextWriter.EnterStyle 方法

定義

寫入標記項目的開頭標記,該標記項目包含實作指定樣式之配置和字元格式的屬性。

多載

EnterStyle(Style)

寫入 <span> 項目的開頭標記,該項目包含實作指定樣式之配置和字元格式的屬性。

EnterStyle(Style, HtmlTextWriterTag)

寫入標記項目的開頭標記,該標記項目包含實作指定樣式之配置和字元格式的屬性。

EnterStyle(Style)

寫入 <span> 項目的開頭標記,該項目包含實作指定樣式之配置和字元格式的屬性。

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)

參數

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

備註

EnterStyle使用 方法可將背景色彩或框線寬度等樣式套用至標記區塊。

EnterStyleExitStyle 方法可讓裝置配接器或控制項建立標記,以使用指定樣式的字元格式設定。 在對應 ExitStyle 方法中使用的 方法中 EnterStyle ,使用相同的值 style

EnterStyle方法的多 EnterStyle(Style) 載會轉譯專案的開頭標記 <span> 。 接著,這個方法會將必要的屬性和樣式屬性新增至專案的開頭標記 <span> ,以顯示 物件所 Style 指定的設定。 如果您想要轉譯不同的標記專案以包含屬性和樣式屬性,請使用 多 EnterStyle(Style, HtmlTextWriterTag) 載。

另請參閱

適用於

EnterStyle(Style, HtmlTextWriterTag)

寫入標記項目的開頭標記,該標記項目包含實作指定樣式之配置和字元格式的屬性。

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)

參數

style
Style

Style,指定開始套用至標記區塊的配置和格式。

tag
HtmlTextWriterTag

HtmlTextWriterTag,指定標記項目的開頭標記 (此標記將包含 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

備註

EnterStyle使用 方法可將背景色彩或框線寬度等樣式套用至標記區塊。

EnterStyleExitStyle 方法可讓裝置配接器或控制項建立標記,以使用指定樣式的字元格式設定。 在對應 ExitStyle 方法中使用的 方法中 EnterStyle ,使用相同的值 style

EnterStyle方法的多 EnterStyle(Style, HtmlTextWriterTag) 載會轉譯 參數所 tag 指定專案的開頭標記。 然後,方法 EnterStyle(Style, HtmlTextWriterTag) 會將必要的屬性和樣式屬性新增至專案的開頭標記,以顯示 物件所 Style 指定的設定。 EnterStyle(Style)使用多載來轉譯專案的 <span> 開頭標記。

另請參閱

適用於