Menu Layout
Menus are built up from MenuItem components. These can be arranged
across the screen on the menu bar, and are most often arranged vertically in
drop-down menus. You can change the default layout of MenuItems to give
a different UI style.
The Break and BarBreak methods are used to create menus that
are arranged horizontally rather than vertically. Setting the BarBreak
property in a MenuItem causes the item to be drawn in a new column.
BarBreak adds a vertical separator bar to the menu between the columns.
Break makes a new column but doesn't add the vertical bar. The
modifications to the menus.cs code on lines 14 and 20 in the following
result in the change seen in Figure 3.1.7.
MenuItem filemenu = new MenuItem();
filemenu.Text = "&File";
menu.MenuItems.Add(filemenu);
MenuItem open = new MenuItem();
open.Text = "&Open";
open.Select += new EventHandler(ShowInfo);
filemenu.MenuItems.Add(open);
MenuItem save= new MenuItem();
save.Text = "&Save";
save.Select += new EventHandler(ShowInfo);
filemenu.MenuItems.Add(save);
save.BarBreak=true;
MenuItem exit= new MenuItem();
exit.Text = "E&xit";
exit.Select += new EventHandler(ShowInfo);
filemenu.MenuItems.Add(exit);
exit.Break=true;
Figure 3.1.7
The BarBreak property.
Similarly, the code changes to lines 14 and 20 in the following result in the
menu style shown in Figure 3.1.8.
MenuItem filemenu = new MenuItem();
filemenu.Text = "&File";
menu.MenuItems.Add(filemenu);
MenuItem open = new MenuItem();
open.Text = "&Open";
open.Select += new EventHandler(ShowInfo);
filemenu.MenuItems.Add(open);
MenuItem save= new MenuItem();
save.Text = "&Save";
save.Select += new EventHandler(ShowInfo);
filemenu.MenuItems.Add(save);
//save.BarBreak=true;
MenuItem exit= new MenuItem();
exit.Text = "E&xit";
exit.Select += new EventHandler(ShowInfo);
filemenu.MenuItems.Add(exit);
exit.Break=true;
Figure 3.1.8
The Break Property in use.
Each time you set the Break property, the MenuItem is placed
in a new column.
Right-to-Left Menus
To cater to cultures that read right-to-left or to add an unconventional style
to your menus, you can modify the menu's RightToLeft property.
1: MainMenu menu = new MainMenu();
2: menu.RightToLeft=RightToLeft.Yes;
3: MenuItem filemenu = new MenuItem();
4: filemenu.Text = "&File";
Adding line 2 to resize.cs results in the effect seen in Figure 3.1.9.
Figure 3.1.9
Right-to-left reading menus.