Language

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メソッドを使用して、背景色や境界線の幅などのスタイルをマークアップ ブロックに適用します。

EnterStyleメソッドと ExitStyle メソッドを使用すると、デバイス アダプターまたはコントロールで、指定したスタイルの文字書式を使用するマークアップを作成できます。 対応する style メソッドで使用するEnterStyle メソッドのExitStyleに同じ値を使用します。

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メソッドを使用して、背景色や境界線の幅などのスタイルをマークアップ ブロックに適用します。

EnterStyleメソッドと ExitStyle メソッドを使用すると、デバイス アダプターまたはコントロールで、指定したスタイルの文字書式を使用するマークアップを作成できます。 対応する style メソッドで使用するEnterStyle メソッドのExitStyleに同じ値を使用します。

EnterStyle メソッドのEnterStyle(Style, HtmlTextWriterTag) オーバーロードは、tag パラメーターで指定された要素の開始タグをレンダリングします。 次に、 EnterStyle(Style, HtmlTextWriterTag) メソッドは、要素の開始タグに必要な属性とスタイル属性を追加して、 Style オブジェクトで指定された設定を表示します。 EnterStyle(Style)オーバーロードを使用して、<span>要素の開始タグをレンダリングします。

こちらもご覧ください

適用対象