Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Book Cover C# and the .NET Framework
63635 times
Rated
Read 63,635 times

Contents

Related Categories

Introduction to Windows Forms - Sub-Menus

Sub-Menus

MenuItem objects in Windows Forms have their own MenuItem collections. This allows you to create a hierarchical structure of menus that have their own cascading child menus within them. The following listing illustrates this process.

  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);

As before, the indentation shows the menu level. Figure 3.1.10 shows the menu in action.

Figure 3.1.10
Submenus in action.

Comments

  • Re: [1770] Introduction to Windows Forms

    Posted by Dracorat on 13 Aug 2008

    Actually all you have to do in place an ampersand before the letter you want underlined.

    So if you want the "r" in "Print" underlined, enter in the code:

    "P&rint"

    That's ...

  • short-cuts

    Posted by rholden on 15 Jul 2005

    this is not a programming issue and it is not something you can set unless you have a custom menu control.

    if you want to view the _ all the time for alt shortcuts you have to go to:

    display pro...

  • Sort-cuts

    Posted by DotDot on 15 May 2003

    The "_" on the short-cut character is visible only when "ALT" is pressed. Is it possible to display the "_" programatically???:confused: