Library sample chapters
Introduction to Windows Forms
Sample chapter from C# and the .NET Framework
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.
Related articles
Related discussion
-
Help me how to dynamic create row column of TableLayoutpanel at run time ??????
by anatha1 (0 replies)
-
Very Urgent regarding deleting the images from a folder
by rameshbandi (2 replies)
-
How to Export Datagridview contents to Excel
by BarbaMariolino (8 replies)
-
Help accessing sound card
by daz4904 (0 replies)
-
How to Write a GPS Application
by stoyac (19 replies)
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 it.
if you want to view the _ all the time for alt shortcuts you have to go to:
display properties->appearance->effects
and uncheck the "Hide underlined charactors for keyboard navigation until I press the ALT key" checkbox.
these instructions are for XP SP2 Pro build 2600
The "" on the short-cut character is visible only when "ALT" is pressed. Is it possible to display the "" programatically???
This thread is for discussions of Introduction to Windows Forms.