HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) Method

定義

指定した HtmlTextWriterStyle 列挙値に関連付けられたマークアップ スタイル属性名を取得します。Obtains the markup style attribute name associated with the specified HtmlTextWriterStyle enumeration value.

protected:
 System::String ^ GetStyleName(System::Web::UI::HtmlTextWriterStyle styleKey);
protected string GetStyleName (System.Web.UI.HtmlTextWriterStyle styleKey);
member this.GetStyleName : System.Web.UI.HtmlTextWriterStyle -> string
Protected Function GetStyleName (styleKey As HtmlTextWriterStyle) As String

パラメーター

styleKey
HtmlTextWriterStyle HtmlTextWriterStyle HtmlTextWriterStyle HtmlTextWriterStyle

スタイル属性名の取得対象の HtmlTextWriterStyleThe HtmlTextWriterStyle to obtain the style attribute name for.

戻り値

styleKey で指定された HtmlTextWriterStyle 列挙値に関連付けられたスタイル属性名。The style attribute name associated with the HtmlTextWriterStyle enumeration value specified in styleKey.

次のコード例を確認する方法を示して かどうかを<label>要素を表示します。The following code example shows how to check whether a <label> element is being rendered. 場合、チェック、かどうかをColorスタイル属性が要素で定義されています。If so, it checks whether a Color style attribute has been defined on the element. 属性が定義されていない場合、AddStyleAttributeメソッドが呼び出されると、GetStyleNameメソッドに変換します、Color列挙型のメンバーに渡すには、その文字列形式へ、AddStyleAttributeメソッド。If the attribute has not been defined, the AddStyleAttribute method is called and the GetStyleName method converts the Color enumeration member into its string representation to pass to the AddStyleAttribute method.

// If the markup element being rendered is a Label,
// render the opening tag of a <Font> element before it.
if ( tagKey == HtmlTextWriterTag::Label )
{
   
   // Check whether a Color style attribute is
   // included on the Label. If not, use the
   // AddStyleAttribute and GetStyleName methods to add one
   // and set its value to red.
   if (  !IsStyleAttributeDefined( HtmlTextWriterStyle::Color ) )
   {
      AddStyleAttribute( GetStyleName( HtmlTextWriterStyle::Color ), "red" );
   }

// If the markup element being rendered is a Label,
// render the opening tag of a Font element before it.
if (tagKey == HtmlTextWriterTag.Label)
{
    // Check whether a Color style attribute is 
    // included on the Label. If not, use the
    // AddStyleAttribute and GetStyleName methods to add one
    // and set its value to red.
    if (!IsStyleAttributeDefined(HtmlTextWriterStyle.Color))
    {
        AddStyleAttribute(GetStyleName(HtmlTextWriterStyle.Color), "red");
    }
' If the markup element being rendered is a Label,
' render the opening tag of a Font element before it.
If tagKey = HtmlTextWriterTag.Label Then
    ' Check whether a Color style attribute is 
    ' included on the Label. If not, use the
    ' AddStyleAttribute and GetStyleName methods to add one
    ' and set its value to red.
    If Not IsStyleAttributeDefined(HtmlTextWriterStyle.Color) Then
        AddStyleAttribute(GetStyleName(HtmlTextWriterStyle.Color), "red")
    End If

注釈

場合styleKeyは無効なHtmlTextWriterStyleオブジェクト、GetStyleNameメソッドは空の文字列を返します ("")。If styleKey is not a valid HtmlTextWriterStyle object, the GetStyleName method returns an empty string ("").

適用対象

こちらもご覧ください