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

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

MenuItemStyleCollection.Add メソッド

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

指定した MenuItemStyle オブジェクト現在のコレクション末尾追加します

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

Public Function Add ( _
    style As MenuItemStyle _
) As Integer
Dim instance As MenuItemStyleCollection
Dim style As MenuItemStyle
Dim returnValue As Integer

returnValue = instance.Add(style)
public int Add (
    MenuItemStyle style
)
public:
int Add (
    MenuItemStyle^ style
)
public int Add (
    MenuItemStyle style
)
public function Add (
    style : MenuItemStyle
) : int

パラメータ

style

現在のコレクション末尾追加する MenuItemStyle。

戻り値
追加されMenuItemStyle の 0 から始まるインデックス番号

解説解説
使用例使用例

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>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MenuItemStyleCollection クラス
MenuItemStyleCollection メンバ
System.Web.UI.WebControls 名前空間
Menu クラス
MenuItem クラス
MenuItemStyle クラス
StyleCollection
SubMenuStyle
SubMenuStyleCollection
Menu.LevelMenuItemStyles プロパティ
Menu.LevelSelectedStyles プロパティ


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS