HtmlTextWriter.GetStyleKey メソッド
アセンブリ: System.Web (system.web.dll 内)

Dim styleName As String Dim returnValue As HtmlTextWriterStyle returnValue = Me.GetStyleKey(styleName)
戻り値
styleName に対応する HtmlTextWriterStyle 列挙値。

styleName がどの HtmlTextWriterStyle 属性値にも対応しない場合、GetStyleKey メソッドは、HtmlTextWriterStyle 値として型指定された値 -1 を返します。

HtmlTextWriter から派生したクラスの RenderBeginTag メソッドをオーバーライドする方法を次のコード例に示します。RenderBeginTag オーバーライドは、<label> マークアップを出力するかどうかを決定します。出力する場合は、Color 属性の要素をチェックします。Color 属性が定義されていない場合は、AddStyleAttribute メソッド呼び出しの 1 番目のパラメータとして GetStyleKey メソッドを使用して、Color 属性を <label> マークアップ要素に追加し、Color 属性を red に設定します。
' Override the RenderBeginTag method to check whether ' the tagKey parameter is set to a <label> element ' or a <font> element. Public Overloads Overrides Sub RenderBeginTag(ByVal tagKey As HtmlTextWriterTag) ' If the tagKey parameter is set to a <label> element ' but a color attribute is not defined on the element, ' the AddStyleAttribute method adds a color attribute ' and sets it to red. If tagKey = HtmlTextWriterTag.Label Then If Not IsStyleAttributeDefined(HtmlTextWriterStyle.Color) Then AddStyleAttribute(GetStyleKey("color"), "red") End If End If ' If the tagKey parameter is set to a <font> element ' but a size attribute is not defined on the element, ' the AddStyleAttribute method adds a size attribute ' and sets it to 30 point. If tagKey = HtmlTextWriterTag.Font Then If Not IsAttributeDefined(HtmlTextWriterAttribute.Size) Then AddAttribute(GetAttributeKey("size"), "30pt") End If End If ' Call the base class's RenderBeginTag method ' to ensure that this custom MarkupTextWriter ' includes functionality for all other markup elements. MyBase.RenderBeginTag(tagKey) End Sub
// Override the RenderBeginTag method to check whether // the tagKey parameter is set to a <label> element // or a <font> element. public override void RenderBeginTag(HtmlTextWriterTag tagKey) { // If the tagKey parameter is set to a <label> element // but a color attribute is not defined on the element, // the AddStyleAttribute method adds a color attribute // and sets it to red. if (tagKey == HtmlTextWriterTag.Label) { if (!IsStyleAttributeDefined(HtmlTextWriterStyle.Color)) { AddStyleAttribute(GetStyleKey("color"), "red"); } } // If the tagKey parameter is set to a <font> element // but a size attribute is not defined on the element, // the AddStyleAttribute method adds a size attribute // and sets it to 30 point. if (tagKey == HtmlTextWriterTag.Font) { if (!IsAttributeDefined(HtmlTextWriterAttribute.Size)) { AddAttribute(GetAttributeKey("size"), "30pt"); } } // Call the base class's RenderBeginTag method // to ensure that this custom MarkupTextWriter // includes functionality for all other markup elements. base.RenderBeginTag(tagKey); }
// Override the RenderBeginTag method to check whether // the tagKey parameter is set to a <label> element // or a <font> element. virtual void RenderBeginTag( HtmlTextWriterTag tagKey ) override { // If the tagKey parameter is set to a <label> element // but a color attribute is not defined on the element, // the AddStyleAttribute method adds a color attribute // and sets it to red. if ( tagKey == HtmlTextWriterTag::Label ) { if ( !IsStyleAttributeDefined( HtmlTextWriterStyle::Color ) ) { AddStyleAttribute( GetStyleKey( "color" ), "red" ); } } // If the tagKey parameter is set to a <font> element // but a size attribute is not defined on the element, // the AddStyleAttribute method adds a size attribute // and sets it to 30 point. if ( tagKey == HtmlTextWriterTag::Font ) { if ( !IsAttributeDefined( HtmlTextWriterAttribute::Size ) ) { AddAttribute( GetAttributeKey( "size" ), "30pt" ); } } // Call the base class's RenderBeginTag method // to ensure that calling this custom markup writer // includes functionality for all other elements. __super::RenderBeginTag( tagKey ); }
// Override the RenderBeginTag method to check whether // the tagKey parameter is set to a <label> element // or a <font> element. public void RenderBeginTag(HtmlTextWriterTag tagKey) { // If the tagKey parameter is set to a Label element // but a Color attribute is not defined on the element, // the AddStyleAttribute method call adds a Color attribute // and sets it to red. if (tagKey.Equals(HtmlTextWriterTag.Label)) { if (!(IsStyleAttributeDefined(HtmlTextWriterStyle.Color))) { AddStyleAttribute(GetStyleKey("color"), "red"); } } // If the tagKey parameter is set to a <font> element // but a size attribute is not defined on the element, // the AddStyleAttribute method call adds a size attribute // and sets it to 30 point. if (tagKey.Equals(HtmlTextWriterTag.Font)) { if (!(IsAttributeDefined(HtmlTextWriterAttribute.Size))) { AddAttribute(GetAttributeKey("size"), "30pt"); } } // Call the base class's RenderBeginTag method // to ensure that calling this custom HtmlTextWriter // includes functionality for all other HTML elements. super.RenderBeginTag(tagKey); } //RenderBeginTag

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


HtmlTextWriter クラス
HtmlTextWriter メンバ
System.Web.UI 名前空間
TextWriter
HtmlTextWriterStyle
AddStyleAttribute
Weblioに収録されているすべての辞書からHtmlTextWriter.GetStyleKey メソッドを検索する場合は、下記のリンクをクリックしてください。

- HtmlTextWriter.GetStyleKey メソッドのページへのリンク