ComponentOne Menus and Toolbars for WinForms
Adding a Submenu
Menus and Toolbars for WinForms Task-Based Help > Menu Tasks > Adding a Submenu

You can add a submenu through the designer or through code. Click on either of the following links to expand the steps for the designer or for the code.

To add a submenu item to C1MainMenu at design time

To add a new command link to the menu (C1CommandMenu or C1ContextMenu) linked by the currently selected command link, complete the following steps:

Note: This item is disabled unless the current command link is linked to a C1CommandMenu or C1ContextMenu type command.
  1. Right-click on an existing menu item in the C1MainMenu and select Add Child Item from the context menu.
    The Link to Command designer appears.
  2. Type submenu 1 in the Text textbox field and select OK. The menu appears like the following menu:

To add a submenu item to C1MainMenu programmatically

To programmatically add a submenu item, complete the following steps:

  1. Add the C1.Win.C1Command namespace to your references in your project.
  2. Declare the namespace in your source file.

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Imports C1.Win.C1Command
    

    To write code in C#

    C#
    Copy Code
    using C1.Win.C1Command;
    
  3. Double-click the form to create a Form_Load event handler, then insert the following code snippets from the remaining steps into the Form_Load event handler.
  4. Add a C1CommandHolder to hold the menu, then create a new main menu.

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim ch As C1CommandHolder = C1CommandHolder.CreateCommandHolder(Me)
    Dim mm As New C1MainMenu
    

    To write code in C#

    C#
    Copy Code
    C1CommandHolder ch = C1CommandHolder.CreateCommandHolder(this);
    C1MainMenu mm = new C1MainMenu();
    
  5.  Add the main menu control to your form, create the main menu to hold the commands, and then set the text property for the new menu.

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Me.Controls.Add(mm)
    Dim mmenu As C1CommandMenu = CType(ch.CreateCommand(GetType(C1CommandMenu)), C1CommandMenu)
    mmenu.Text = "Menu 1"
    

    To write code in C#

    C#
    Copy Code
    this.Controls.Add(mm);
    C1CommandMenu mmenu = ch.CreateCommand(typeof(C1CommandMenu)) as C1CommandMenu;
    mmenu.Text = "Menu 1";
    
  6. Add the commandlink to the new main menu, then create and set up a menu item under menu 1. Fill the menu with a command.

    To write code in Visual Basic

    Visual Basic
    Copy Code
    mm.CommandLinks.Add(New C1CommandLink(mmenu))
    Dim submenu As C1Command = ch.CreateCommand()
    

    To write code in C#

    C#
    Copy Code
    mm.CommandLinks.Add(new C1CommandLink(mmenu));
    C1Command submenu = ch.CreateCommand();
    
  7. Add text to the new submenu item and add a new c1commandlink to the submenu item.

    To write code in Visual Basic

    Visual Basic
    Copy Code
    submenu.Text = "submmenu 1"
    'add a new c1commandlink to the submenu item
    mmenu.CommandLinks.Add(New C1CommandLink(submenu))
    

    To write code in C#

    C#
    Copy Code
    submenu.Text = "submenu 1";
    //add a new c1commandlink to the submenu item
    mmenu.CommandLinks.Add(new C1CommandLink(submenu));
    

    Your menu should appear like the following menu:
See Also