HtmlTextWriter.EnterStyle 方法

定義

寫入標記項目的開頭標記,該標記項目包含實作指定樣式之配置和字元格式的屬性。Writes the opening tag of a markup element that contains attributes that implement the layout and character formatting of the specified style.

多載

EnterStyle(Style)

寫入 <span> 項目的開頭標記,該項目包含實作指定樣式之配置和字元格式的屬性。Writes the opening tag of a <span> element that contains attributes that implement the layout and character formatting of the specified style.

EnterStyle(Style, HtmlTextWriterTag)

寫入標記項目的開頭標記,該標記項目包含實作指定樣式之配置和字元格式的屬性。Writes the opening tag of a markup element that contains attributes that implement the layout and character formatting of the specified style.

EnterStyle(Style)

寫入 <span> 項目的開頭標記,該項目包含實作指定樣式之配置和字元格式的屬性。Writes the opening tag of a <span> element that contains attributes that implement the layout and character formatting of the specified style.

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

參數

style
Style

Style,指定開始套用至標記區塊的配置和格式。A Style that specifies the layout and formatting to begin applying to the block of markup.

範例

下列程式碼範例示範TextSample如何使用名為的自訂類別(衍生WebControlEnterStyle類別),它會使用方法ForeColor將樣式套用至文字字串。The following code example demonstrates how to use a custom class named TextSample, derived from the WebControl class, that uses the EnterStyle method to apply a ForeColor style to a string of text.

方法會呈現 HTML <span style="color:Navy;">EnterStyleThe EnterStyle method renders the HTML <span style="color:Navy;">. 方法呼叫會在呈現<span>文字之後關閉元素。 ExitStyleThe ExitStyle method call closes the <span> element after the text has been rendered.

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使用方法,將樣式(例如背景色彩或框線寬度)套用至標記的區塊。Use the EnterStyle method to apply styles, such as background color or border width, to a block of markup.

EnterStyleExitStyle方法可讓裝置介面卡或控制項建立使用指定樣式之字元格式的標記。The EnterStyle and ExitStyle methods allow a device adapter or control to create markup that uses the character formatting of the specified style. style 在您ExitStyle于對應的方法中使用的方法中,使用與相同的值。EnterStyleUse the same value for style in the EnterStyle method that you use in the corresponding ExitStyle method.

方法的EnterStyle多載會呈現<span>元素的開頭標記。 EnterStyle(Style)The EnterStyle overload of the EnterStyle(Style) method renders the opening tag of a <span> element. 然後,這個方法會將必要的屬性和樣式屬性加入至專案的<span>開頭標記,以顯示Style物件所指定的設定。This method then adds the necessary attributes and style attributes to the opening tag of the <span> element to display the settings specified by the Style object. 如果您想要呈現不同的標記專案來包含屬性和樣式屬性,請使用EnterStyle(Style, HtmlTextWriterTag)多載。If you want to render a different markup element to contain the attributes and style attributes, use the EnterStyle(Style, HtmlTextWriterTag) overload.

另請參閱

EnterStyle(Style, HtmlTextWriterTag)

寫入標記項目的開頭標記,該標記項目包含實作指定樣式之配置和字元格式的屬性。Writes the opening tag of a markup element that contains attributes that implement the layout and character formatting of the specified style.

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

參數

style
Style

Style,指定開始套用至標記區塊的配置和格式。A Style that specifies the layout and formatting to begin applying to the block of markup.

tag
HtmlTextWriterTag

HtmlTextWriterTag,指定標記項目的開頭標記 (此標記將包含 style 中所指定的樣式物件)。An HtmlTextWriterTag that specifies the opening tag of the markup element that will contain the style object specified in style.

範例

下列程式碼範例示範TextSample如何使用名為的自訂類別(衍生WebControlEnterStyle類別),它會使用方法ForeColor將樣式套用至文字字串。The following code example demonstrates how to use a custom class named TextSample, derived from the WebControl class, that uses the EnterStyle method to apply a ForeColor style to a string of text.

方法會呈現 HTML<span style="color:Navy;">EnterStyleThe EnterStyle method renders the HTML<span style="color:Navy;">. 方法呼叫會在呈現<span>文字之後關閉元素。 ExitStyleThe ExitStyle method call closes the <span> element after the text has been rendered.

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使用方法,將樣式(例如背景色彩或框線寬度)套用至標記的區塊。Use the EnterStyle method to apply styles, such as background color or border width, to a block of markup.

EnterStyleExitStyle方法可讓裝置介面卡或控制項建立使用指定樣式之字元格式的標記。The EnterStyle and ExitStyle methods allow a device adapter or control to create markup that uses the character formatting of the specified style. style 在您ExitStyle于對應的方法中使用的方法中,使用與相同的值。EnterStyleUse the same value for style in the EnterStyle method that you use in the corresponding ExitStyle method.

方法的EnterStyle多載會呈現tag參數所指定之專案的開頭標記。 EnterStyle(Style, HtmlTextWriterTag)The EnterStyle overload of the EnterStyle(Style, HtmlTextWriterTag) method renders the opening tag of the element specified by the tag parameter. 然後EnterStyle(Style, HtmlTextWriterTag) ,方法會將必要的屬性和樣式屬性加入至專案的開頭標記,以顯示Style物件所指定的設定。The EnterStyle(Style, HtmlTextWriterTag) method then adds the necessary attributes and style attributes to the opening tag of the element to display the settings that are specified by the Style object. 使用多載來轉譯<span>元素的開頭標記。 EnterStyle(Style)Use the EnterStyle(Style) overload to render the opening tag of a <span> element.

另請參閱

適用於