Library sample chapters
Introduction to Windows Forms
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.
Related articles
Related discussion
-
C# video Editing/rendering
by pkuchaliya (0 replies)
-
How to Fill DataSet with more records (around 1 lakh) in a faster way
by Jayaram P (0 replies)
-
Can't print on the network with MSADESS ??
by anatha1 (2 replies)
-
Very Urgent regarding deleting the images from a folder
by Nanosteps (6 replies)
-
DataGridViewComboBoxColumn not showing values
by sachinkalse (0 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.