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
Public Overridable Sub EnterStyle (style As Style)

参数

style
Style

一个 Style,用于指定要开始应用到标记块的布局和格式设置。A Style that specifies the layout and formatting to begin applying to the block of markup.

示例

下面的代码示例演示如何使用派生自 WebControl 类的名为 TextSample的自定义类,该自定义类使用 EnterStyle 方法将 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.

EnterStyle 方法将呈现 HTML <span style="color:Navy;">The EnterStyle method renders the HTML <span style="color:Navy;">. ExitStyle 方法调用在呈现文本后关闭 <span> 元素。The 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. 使用与在相应 ExitStyle 方法中使用的 EnterStyle 方法中 style 相同的值。Use the same value for style in the EnterStyle method that you use in the corresponding ExitStyle method.

EnterStyle(Style) 方法的 EnterStyle 重载将呈现 <span> 元素的开始标记。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
Public Overridable Sub EnterStyle (style As Style, tag As HtmlTextWriterTag)

参数

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.

示例

下面的代码示例演示如何使用派生自 WebControl 类的名为 TextSample的自定义类,该自定义类使用 EnterStyle 方法将 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.

EnterStyle 方法将呈现 HTML<span style="color:Navy;">The EnterStyle method renders the HTML<span style="color:Navy;">. ExitStyle 方法调用在呈现文本后关闭 <span> 元素。The 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. 使用与在相应 ExitStyle 方法中使用的 EnterStyle 方法中 style 相同的值。Use the same value for style in the EnterStyle method that you use in the corresponding ExitStyle method.

EnterStyle(Style, HtmlTextWriterTag) 方法的 EnterStyle 重载将呈现由 tag 参数指定的元素的开始标记。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. 使用 EnterStyle(Style) 重载可呈现 <span> 元素的开始标记。Use the EnterStyle(Style) overload to render the opening tag of a <span> element.

另请参阅

适用于