MenuItemStyleCollectionとは? わかりやすく解説

MenuItemStyleCollection クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

Menu コントロール内の MenuItemStyle オブジェクトのコレクションを表します。このクラスは継承できません。

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

Public NotInheritable Class
 MenuItemStyleCollection
    Inherits StateManagedCollection
Dim instance As MenuItemStyleCollection
public sealed class MenuItemStyleCollection
 : StateManagedCollection
public ref class MenuItemStyleCollection sealed
 : public StateManagedCollection
public final class MenuItemStyleCollection
 extends StateManagedCollection
public final class MenuItemStyleCollection
 extends StateManagedCollection
解説解説

MenuItemStyleCollection クラスは、Menu コントロール内の MenuItemStyle オブジェクトのコレクションを格納および管理する場合に使用されます。Menu コントロールは、MenuItemStyleCollection クラスを、LevelMenuItemStyles プロパティおよび LevelSelectedStyles プロパティの基になるデータ型として使用します。

LevelMenuItemStyles プロパティと LevelSelectedStyles プロパティは、個々のスタイル プロパティ (StaticMenuItemStyle など) の代わりに使用します。これらのプロパティは、メニュー内のメニュー項目レベルに基づいて、それぞれ標準のメニュー項目と選択されたメニュー項目に適用されます。このコレクションの中の最初のスタイルは、メニューの最初のレベルのメニュー項目スタイルに対応します。このコレクションの中の 2 番目のスタイルは、メニューの 2 番目のレベルのメニュー項目スタイルに対応し、以下同様に対応します。LevelMenuItemStyles プロパティと LevelSelectedStyles プロパティが最も多く使われるのは、サブメニューの有無にかかわらず、特定のレベルにあるメニュー項目の外観が同じメニューを生成する場合です。

MenuItemStyleCollection クラスは、StateManagedCollection クラスのほとんどのメンバを継承します。継承メンバの詳細については、StateManagedCollection のトピックを参照してください。

使用例使用例

MenuItemStyleCollection クラスを使用して、メニュー項目のレベルに基づいて Menu コントロールのメニュー項目にスタイル設定を指定する方法のコード例を次に示します。この例では、LevelMenuItemStyles プロパティが宣言によって作成され、1 つの MenuItemStyle オブジェクトが削除され、別のオブジェクトが MenuItemStyleCollection オブジェクトに追加されています。

<%@ Page Language="VB" %>

<script runat="server">

Sub Page_Load(ByVal sender As
 [Object], ByVal e As EventArgs) 
    
    If Not IsPostBack Then
        
        ' Use the Add and RemoveAt methods to programmatically 
        ' remove the third level menu item style and replace 
        ' it with a new style, in this case replacing the green background
        ' and yellow text with the blue background and white text. 
        Dim newStyle As New
 MenuItemStyle()
        newStyle.BackColor = System.Drawing.Color.Blue
        newStyle.ForeColor = System.Drawing.Color.White
        
        ' Remove the last of the three menu item styles. Note that
        ' since the collection has a zero-based index, the third
        ' entry has an index value of 2.
        MainMenuID.LevelMenuItemStyles.RemoveAt(2)
        MainMenuID.LevelMenuItemStyles.Add(newStyle)
    End If
 
End Sub 'Page_Load
</script>

<html>
  <body>
    <form runat="server">
    
      <h3>MenuItemStyleCollection Example</h3>
         <!--Add MenuItemStyle objects to the MenuItemStyleCollection
 -->
         <!--using LevelMenuItemStyles.   -->
         <!--Note that each menu item style represents a level
 in the menu -->

      <asp:Menu id="MainMenuID"
       Font-Names= "Arial"
        ForeColor="Blue"
        runat="server">
         
         <LevelMenuItemStyles>
         <asp:MenuItemStyle BackColor="Azure" 
             Font-Italic="true"
             Font-Names="Arial"
             ForeColor="Black" />
         
           <asp:MenuItemStyle BackColor="Black"
 
             Font-Italic="false"
             Font-Names="Arial"
             ForeColor="White" />
             
         <asp:MenuItemStyle BackColor="Green" 
             Font-Italic="true"
             Font-Names="Arial"
             ForeColor="Yellow" />
       
         </LevelMenuItemStyles>

        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Music"
              tooltip="Music">
              <asp:menuitem text="Classical"
                tooltip="Classical"/>
              <asp:menuitem text="Rock"
                tooltip="Rock"/>
              <asp:menuitem text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem text="Movies"
              tooltip="Movies">
              <asp:menuitem text="Action"
                tooltip="Action"/>
              <asp:menuitem text="Drama"
                tooltip="Drama"/>
              <asp:menuitem text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>

        
      </asp:Menu>

    </form>
  </body>
</html>

<%@ Page Language="C#" %>

<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {

    if (!IsPostBack)
    {

      // Use the Add and RemoveAt methods to programmatically 
      // remove the third level menu item style and replace 
      // it with a new style, in this case replacing the green background
        // and yellow text with the blue background and white text.
 

        MenuItemStyle newStyle = new MenuItemStyle();
        newStyle.BackColor = System.Drawing.Color.Blue;
        newStyle.ForeColor = System.Drawing.Color.White;

        // Remove the last of the three menu item styles. Note that
        // since the collection has a zero-based index, the third
        // entry has an index value of 2.
        MainMenuID.LevelMenuItemStyles.RemoveAt(2);
        MainMenuID.LevelMenuItemStyles.Add(newStyle);

    }

  }

</script>

<html>
  <body>
    <form runat="server">
    
      <h3>MenuItemStyleCollection Example</h3>
         <!--Add MenuItemStyle objects to the MenuItemStyleCollection -->
         <!--using LevelMenuItemStyles.  -->
         <!--Note that each menu item style represents a level in
 the menu -->

      <asp:Menu id="MainMenuID"
       Font-Names= "Arial"
        ForeColor="Blue"
        runat="server">
         
         <LevelMenuItemStyles>
         <asp:MenuItemStyle BackColor="Azure" 
             Font-Italic="true"
             Font-Names="Arial"
             ForeColor="Black" />
         
           <asp:MenuItemStyle BackColor="Black" 
             Font-Italic="false"
             Font-Names="Arial"
             ForeColor="White" />
             
         <asp:MenuItemStyle BackColor="Green" 
             Font-Italic="true"
             Font-Names="Arial"
             ForeColor="Yellow" />
       
         </LevelMenuItemStyles>

        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Music"
              tooltip="Music">
              <asp:menuitem text="Classical"
                tooltip="Classical"/>
              <asp:menuitem text="Rock"
                tooltip="Rock"/>
              <asp:menuitem text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem text="Movies"
              tooltip="Movies">
              <asp:menuitem text="Action"
                tooltip="Action"/>
              <asp:menuitem text="Drama"
                tooltip="Drama"/>
              <asp:menuitem text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>

        
      </asp:Menu>

    </form>
  </body>
</html>

.NET Framework のセキュリティ.NET Framework のセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.StateManagedCollection
    System.Web.UI.WebControls.MenuItemStyleCollection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MenuItemStyleCollection メンバ
System.Web.UI.WebControls 名前空間
Menu クラス
MenuItem クラス
MenuItemStyle クラス
StyleCollection
SubMenuStyle
SubMenuStyleCollection
Menu.LevelMenuItemStyles プロパティ
Menu.LevelSelectedStyles プロパティ

MenuItemStyleCollection プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Count  StateManagedCollection コレクションに格納されている要素の数を取得します。 ( StateManagedCollection から継承されます。)
パブリック プロパティ Item 指定したインデックス位置にある MenuItemStyle オブジェクトをコレクションから取得します。
参照参照

関連項目

MenuItemStyleCollection クラス
System.Web.UI.WebControls 名前空間
Menu クラス
MenuItem クラス
MenuItemStyle クラス
StyleCollection
SubMenuStyle
SubMenuStyleCollection
Menu.LevelMenuItemStyles プロパティ
Menu.LevelSelectedStyles プロパティ

MenuItemStyleCollection メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Add 指定した MenuItemStyle オブジェクトを現在のコレクションの末尾に追加します。
パブリック メソッド Clear  StateManagedCollection コレクションからすべての項目を削除します。 ( StateManagedCollection から継承されます。)
パブリック メソッド Contains 指定した MenuItemStyle オブジェクトがコレクション内にあるかどうかを確認します。
パブリック メソッド CopyTo オーバーロードされます。 MenuItemStyleCollection オブジェクトからすべての項目をコピーします。
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。)
パブリック メソッド GetEnumerator  StateManagedCollection コレクションを反復処理する反復子を返します。 ( StateManagedCollection から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド IndexOf コレクション内の指定した MenuItemStyle オブジェクトのインデックスを確認します。
パブリック メソッド Insert このコレクション内の指定したインデックス位置に、指定した MenuItemStyle オブジェクトを挿入します。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド Remove 指定した MenuItemStyle オブジェクトをコレクションから削除します。
パブリック メソッド RemoveAt 指定したインデックス位置にある MenuItemStyle オブジェクトをコレクションから削除します。
パブリック メソッド SetDirty  強制的に StateManagedCollection コレクション全体をビューステートにシリアル化します。 ( StateManagedCollection から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

MenuItemStyleCollection クラス
System.Web.UI.WebControls 名前空間
Menu クラス
MenuItem クラス
MenuItemStyle クラス
StyleCollection
SubMenuStyle
SubMenuStyleCollection
Menu.LevelMenuItemStyles プロパティ
Menu.LevelSelectedStyles プロパティ

MenuItemStyleCollection メンバ

Menu コントロール内の MenuItemStyle オブジェクトのコレクションを表します。このクラスは継承できません。

MenuItemStyleCollection データ型で公開されるメンバを以下の表に示します。


パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Count  StateManagedCollection コレクションに格納されている要素の数を取得します。(StateManagedCollection から継承されます。)
パブリック プロパティ Item 指定したインデックス位置にある MenuItemStyle オブジェクトをコレクションから取得します。
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Add 指定した MenuItemStyle オブジェクトを現在のコレクションの末尾に追加します。
パブリック メソッド Clear  StateManagedCollection コレクションからすべての項目を削除します。 (StateManagedCollection から継承されます。)
パブリック メソッド Contains 指定した MenuItemStyle オブジェクトがコレクション内にあるかどうかを確認します。
パブリック メソッド CopyTo オーバーロードされます。 MenuItemStyleCollection オブジェクトからすべての項目をコピーします。
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。)
パブリック メソッド GetEnumerator  StateManagedCollection コレクションを反復処理する反復子を返します。 (StateManagedCollection から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド IndexOf コレクション内の指定した MenuItemStyle オブジェクトのインデックスを確認します。
パブリック メソッド Insert このコレクション内の指定したインデックス位置に、指定した MenuItemStyle オブジェクトを挿入します。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド Remove 指定した MenuItemStyle オブジェクトをコレクションから削除します。
パブリック メソッド RemoveAt 指定したインデックス位置にある MenuItemStyle オブジェクトをコレクションから削除します。
パブリック メソッド SetDirty  強制的に StateManagedCollection コレクション全体をビューステートにシリアル化します。 (StateManagedCollection から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

MenuItemStyleCollection クラス
System.Web.UI.WebControls 名前空間
Menu クラス
MenuItem クラス
MenuItemStyle クラス
StyleCollection
SubMenuStyle
SubMenuStyleCollection
Menu.LevelMenuItemStyles プロパティ
Menu.LevelSelectedStyles プロパティ



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「MenuItemStyleCollection」の関連用語

MenuItemStyleCollectionのお隣キーワード
検索ランキング

   

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



MenuItemStyleCollectionのページの著作権

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

©2026 GRAS Group, Inc.RSS