HtmlTextWriter.GetStyleKey メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HtmlTextWriter.GetStyleKey メソッドの意味・解説 

HtmlTextWriter.GetStyleKey メソッド

指定したスタイルHtmlTextWriterStyle 列挙値を取得します

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Protected Function GetStyleKey ( _
    styleName As String _
) As HtmlTextWriterStyle
Dim styleName As String
Dim returnValue As HtmlTextWriterStyle

returnValue = Me.GetStyleKey(styleName)
protected HtmlTextWriterStyle GetStyleKey (
    string styleName
)
protected:
HtmlTextWriterStyle GetStyleKey (
    String^ styleName
)
protected HtmlTextWriterStyle GetStyleKey (
    String styleName
)
protected function GetStyleKey (
    styleName : String
) : HtmlTextWriterStyle

パラメータ

styleName

HtmlTextWriterStyle の取得対象スタイル属性

戻り値
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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HtmlTextWriter クラス
HtmlTextWriter メンバ
System.Web.UI 名前空間
TextWriter
HtmlTextWriterStyle
AddStyleAttribute


このページでは「.NET Framework クラス ライブラリ リファレンス」からHtmlTextWriter.GetStyleKey メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHtmlTextWriter.GetStyleKey メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHtmlTextWriter.GetStyleKey メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

HtmlTextWriter.GetStyleKey メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HtmlTextWriter.GetStyleKey メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS