Add Submenu : Menu « GUI Windows Forms « C# / CSharp Tutorial






Add Submenu
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;

public class MenuSubMenu : System.Windows.Forms.Form
{
    public  MenuSubMenu()
    {
        MainMenu menu = new MainMenu();

        MenuItem filemenu = new MenuItem();
        filemenu.Text = "&File";
        menu.MenuItems.Add(filemenu);

            MenuItem open = new MenuItem();
            open.Text = "&Open";
            filemenu.MenuItems.Add(open);

            MenuItem print= new MenuItem();
            print.Text = "Print...";
            filemenu.MenuItems.Add(print);

                MenuItem temp= new MenuItem();
                temp.Text = "Pre&view";
                print.MenuItems.Add(temp);

                temp= new MenuItem();
                temp.Text = "To &File";
                print.MenuItems.Add(temp);

            MenuItem exit= new MenuItem();
            exit.Text = "E&xit";
            filemenu.MenuItems.Add(exit);
    
        this.Menu = menu;

        ContextMenu cmenu = new ContextMenu();
        cmenu.MenuItems.Add(new MenuItem("&First"));
        cmenu.MenuItems.Add(new MenuItem("&Second"));
        cmenu.MenuItems.Add(new MenuItem("-"));
        cmenu.MenuItems.Add(new MenuItem("&Third"));

        this.ContextMenu=cmenu;
    }

    static void Main()
    {
        Application.Run(new MenuSubMenu());
    }
}








23.39.Menu
23.39.1.Add Menu to FormAdd Menu to Form
23.39.2.Create a Menu without using the IDECreate a Menu without using the IDE
23.39.3.Menu RightToLeftMenu RightToLeft
23.39.4.Add SubmenuAdd Submenu
23.39.5.Set Label text in menu actionSet Label text in menu action
23.39.6.Context Menu Demo
23.39.7.Context Menu Using Add
23.39.8.Add MenuStrip and ToolStripMenuItem to Form