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


RemoveAt メソッドを使用して、指定した 0 から始まるインデックス位置にある MenuItemStyle オブジェクトをコレクションから削除します。削除されるノードの後に続く項目はすべて、空いた位置を埋め合わせるように上に移動します。移動した項目のインデックスも更新されます。

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>

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からMenuItemStyleCollection.RemoveAt メソッドを検索する場合は、下記のリンクをクリックしてください。

- MenuItemStyleCollection.RemoveAt メソッドのページへのリンク