A well-structured and intuitive user interface is essential for enhancing user experience and navigation. This can be achieved by adding submenus to main menu. The following section provides step-by-step approach to add submenu to C1MainMenu component as shown in the below image:
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:
Run the application to see submenu created under the main menu component.
To add a new command link to the menu (C1CommandMenu or C1ContextMenu) linked by the currently selected command link, complete the following steps:
To add a submenu item to C1MainMenu programmatically
To programmatically add submenu item, complete the following steps:
C# |
Copy Code
|
---|---|
using C1.Win.Command;
|
VB |
Copy Code
|
---|---|
Imports C1.Win.Command |
CS |
Copy Code
|
---|---|
//Add a C1CommandHolder to hold the menu and Create a new main menu. C1CommandHolder ch = C1CommandHolder.CreateCommandHolder(this); C1MainMenu mm = new C1MainMenu(); //Add the main menu control to form. this.Controls.Add(mm); //Create the main menu to hold the command. Set the text property for the new menu. C1CommandMenu mmenu = (C1CommandMenu)ch.CreateCommand(typeof(C1CommandMenu)); mmenu.Text = "Menu 1"; //Add commandlink to the new main menu. mm.CommandLinks.Add(new C1CommandLink(mmenu)); //Create a submenu item as command. Set the text property for submenu. C1Command submenu = ch.CreateCommand(); submenu.Text = "Submenu1"; //Add commandlink to submenu item. mmenu.CommandLinks.Add(new C1CommandLink(submenu)); |
VB |
Copy Code
|
---|---|
'Add a C1CommandHolder to hold the menu and Create a new main menu. Dim ch As C1CommandHolder = C1CommandHolder.CreateCommandHolder(Me) Dim mm As New C1MainMenu 'Add the main menu control to form. Me.Controls.Add(mm) 'Create the main menu to hold the command. Set the text property for the new menu. Dim mmenu As C1CommandMenu = CType(ch.CreateCommand(GetType(C1CommandMenu)), C1CommandMenu) mmenu.Text = "Menu 1" 'Add commandlink to the new main menu. mm.CommandLinks.Add(New C1CommandLink(mmenu)) 'Create a submenu item as command. Set the text property for submenu. Dim submenu As C1Command = ch.CreateCommand() submenu.Text = "Submenu1" 'Add commandlink to submenu item. mmenu.CommandLinks.Add(New C1CommandLink(submenu)) |
Run the code and observe the output.
C# |
Copy Code
|
---|---|
using C1.Win.C1Command;
|
VB |
Copy Code
|
---|---|
Imports C1.Win.C1Command |
CS |
Copy Code
|
---|---|
//Add a C1CommandHolder to hold the menu and Create a new main menu. C1CommandHolder ch = C1CommandHolder.CreateCommandHolder(this); C1MainMenu mm = new C1MainMenu(); //Add the main menu control to form. this.Controls.Add(mm); //Create the main menu to hold the command. Set the text property for the new menu. C1CommandMenu mmenu = (C1CommandMenu)ch.CreateCommand(typeof(C1CommandMenu)); mmenu.Text = "Menu 1"; //Add commandlink to the new main menu. mm.CommandLinks.Add(new C1CommandLink(mmenu)); //Create a submenu item as command. Set the text property for submenu. C1Command submenu = ch.CreateCommand(); submenu.Text = "Submenu1"; //Add commandlink to submenu item. mmenu.CommandLinks.Add(new C1CommandLink(submenu)); |
VB |
Copy Code
|
---|---|
'Add a C1CommandHolder to hold the menu and Create a new main menu. Dim ch As C1CommandHolder = C1CommandHolder.CreateCommandHolder(Me) Dim mm As New C1MainMenu 'Add the main menu control to form. Me.Controls.Add(mm) 'Create the main menu to hold the command. Set the text property for the new menu. Dim mmenu As C1CommandMenu = CType(ch.CreateCommand(GetType(C1CommandMenu)), C1CommandMenu) mmenu.Text = "Menu 1" 'Add commandlink to the new main menu. mm.CommandLinks.Add(New C1CommandLink(mmenu)) 'Create a submenu item as command. Set the text property for submenu. Dim submenu As C1Command = ch.CreateCommand() submenu.Text = "Submenu1" 'Add commandlink to submenu item. mmenu.CommandLinks.Add(New C1CommandLink(submenu)) |
Run the code and observe the output.