HtmlTextWriter.ExitStyle 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
写入标记元素的结束标记以结束指定的布局和字符格式设置。
重载
ExitStyle(Style) |
写入 |
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)
参数
示例
下面的代码示例演示如何使用派生自类的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)
参数
一个 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
。