MenuItemStyleCollection クラス
アセンブリ: System.Web (system.web.dll 内)
構文
解説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 のセキュリティ
継承階層System.Web.UI.StateManagedCollection
System.Web.UI.WebControls.MenuItemStyleCollection
スレッド セーフ
プラットフォーム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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照MenuItemStyleCollection プロパティ
パブリック プロパティ| 名前 | 説明 | |
|---|---|---|
| Count | StateManagedCollection コレクションに格納されている要素の数を取得します。 ( StateManagedCollection から継承されます。) |
| Item | 指定したインデックス位置にある MenuItemStyle オブジェクトをコレクションから取得します。 |
参照MenuItemStyleCollection メソッド
パブリック メソッド
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
参照MenuItemStyleCollection メンバ
Menu コントロール内の MenuItemStyle オブジェクトのコレクションを表します。このクラスは継承できません。
MenuItemStyleCollection データ型で公開されるメンバを以下の表に示します。
パブリック プロパティ| 名前 | 説明 | |
|---|---|---|
| Count | StateManagedCollection コレクションに格納されている要素の数を取得します。(StateManagedCollection から継承されます。) |
| Item | 指定したインデックス位置にある MenuItemStyle オブジェクトをコレクションから取得します。 |
パブリック メソッド
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
参照Weblioに収録されているすべての辞書からMenuItemStyleCollectionを検索する場合は、下記のリンクをクリックしてください。
全ての辞書からMenuItemStyleCollection
を検索
- MenuItemStyleCollectionのページへのリンク