Customizing the Application Menu
The Application Menu is a menu that is displayed when you click on the Office Button in the upper left corner of RadRibbonBar:
The *Application Menu *can contain the same elements as RadMenu. Please refer to RadMenu section of the documentation for further a more comprehensive information about RadMenu. In contrast to RadMenu, menu items can be arranged in two columns.
Assigning an Image to the Application Menu Office Button
RadRibbonBar.StartButtonImage property defines the image used in the Application Menu button. The following code assigns an image (The example assumes that the image is added to the Project Resources):
Assign image to start button
radRibbonBar1.StartButtonImage = new Bitmap("..\\..\\DataSources\\star.png");
RadRibbonBar1.StartButtonImage = New Bitmap("..\\..\\DataSources\\star.png")
Adding Items to the Application Menu
There are five types of items which you can add to the Application Menu:
RadMenuItem | A standard menu item. |
RadMenuButtonItem | A button menu item. |
RadMenuHeaderItem | A header menu item. |
RadMenuSeperatorItem | A separator. |
RadMenuComboItem | A combobox menu item. |
For example to create a new RadMenuItem and add it to the application menu use the following code:
Creating and add new menu item
RadMenuItem mnuNew = new RadMenuItem("New File");
mnuNew.Click += new EventHandler(NewFile);
radRibbonBar1.StartMenuItems.Add(mnuNew);
Dim mnuNew As New RadMenuItem("New File")
AddHandler mnuNew.Click, AddressOf NewFile
RadRibbonBar1.StartMenuItems.Add(mnuNew)
Below is the method that is referred to by the handler of the Click event.
Handle the menu item click event
void NewFile(object sender, EventArgs e)
{
MessageBox.Show("New File code goes here");
}
Private Sub NewFile(sender As Object, e As EventArgs)
MessageBox.Show("New File code goes here")
End Sub
Adding Items to the Right Column
To place items in the right column of the Application Menu use RadRibbonBar.StartMenuRightColumnItems collection. This code adds a RadMenuItem to the right column. The RadMenuItem.Enabled property is set to false so that items will act as labels and clicks will be disallowed.
Adding items to the right column
RadMenuItem mnuRecentDocs = new RadMenuItem("Recent Documents");
mnuRecentDocs.Enabled = false;
radRibbonBar1.StartMenuRightColumnItems.Add(mnuRecentDocs);
Dim mnuRecentDocs As New RadMenuItem("Recent Documents")
mnuRecentDocs.Enabled = False
RadRibbonBar1.StartMenuRightColumnItems.Add(mnuRecentDocs)
Adding Items with Sub Items
To create a submenu under a menu item, add items to the Items collection of the first RadMenuItem.
This code adds a new RadMenuItem, mnuPrint, to the Start Menu. Then another three RadMenuItems are created and added to mnuPrint.Items. Those three items, which make up the submenu, will have their own event handlers for the user click events.
Adding menu items with sub items
RadMenuItem mnuPrint = new RadMenuItem("Print");
//add Print menu item to the Start Menu
radRibbonBar1.StartMenuItems.Add(mnuPrint);
//Create Sub-Menu Items with event handlers
RadMenuItem mnuPrintsubPrint = new RadMenuItem("Print");
mnuPrintsubPrint.Click += new EventHandler(Print);
RadMenuItem mnuPrintsubQuickPrint = new RadMenuItem("Quick Print");
mnuPrintsubQuickPrint.Click += new EventHandler(QuickPrint);
RadMenuItem mnuPrintsubPreview = new RadMenuItem("Print Preview");
mnuPrintsubPreview.Click += new EventHandler(Preview);
//add sub-menu items to start menu
mnuPrint.Items.AddRange(new RadMenuItem[] {mnuPrintsubPrint, mnuPrintsubQuickPrint, mnuPrintsubPreview});
Dim mnuPrint As New RadMenuItem("Print")
'add Print menu item to the Start Menu
RadRibbonBar1.StartMenuItems.Add(mnuPrint)
'Create Sub-Menu Items with event handlers
Dim mnuPrintsubPrint As New RadMenuItem("Print")
AddHandler mnuPrintsubPrint.Click, AddressOf Print
Dim mnuPrintsubQuickPrint As New RadMenuItem("Quick Print")
AddHandler mnuPrintsubQuickPrint.Click, AddressOf QuickPrint
Dim mnuPrintsubPreview As New RadMenuItem("Print Preview")
AddHandler mnuPrintsubPreview.Click, AddressOf Preview
'Add sub-menu items to the Print menu item
mnuPrint.Items.AddRange(New RadMenuItem() {mnuPrintsubPrint, mnuPrintsubQuickPrint, mnuPrintsubPreview})
Wrapping Items' Text
The ApplicationMenu of RadRibbonBar supports wrapping of the main and description texts of its items in the right column. To enable it, you should set the TextWrap property of the Text and Description parts of the menu items to true. In addition, you should set the MaxSize of these parts. Finally, you can set the width of the right column to an appropriate value by the ApplicationMenuRightColumnWidth property. Let's say that we have the following RadMenuItems in the right column:
this.LongNameFileMenuItem.Text = "This is a file with a veeeeeeeery veeeeery long name.png";
this.UntitledFileMenuItem.DescriptionText = "C:\\Program Files (x86)\\Telerik\\RadControls for WinForms Q3 2012\\Resources\\Untitled.png";
this.UntitledFileMenuItem.Text = "Untitled.png";
Me.LongNameFileMenuItem.Text = "This is a file with a veeeeeeeery veeeeery long name.png"
Me.UntitledFileMenuItem.DescriptionText = "C:\\Program Files (x86)\\Telerik\\RadControls for WinForms Q3 2012\\Resources\\Untitled.png"
Me.UntitledFileMenuItem.Text = "Untitled.png"
By default, the menu will look like this:
So, as mentioned above, we should set the TextWrap and MaxSize properties of the Text and Description parts of the menu items:
this.radRibbonBar1.RibbonBarElement.ApplicationMenuRightColumnWidth = 180;
this.LongNameFileMenuItem.Layout.Text.TextWrap = true;
this.LongNameFileMenuItem.Layout.Text.MaxSize = new Size(150, 0);
this.UntitledFileMenuItem.Layout.Description.TextWrap = true;
this.UntitledFileMenuItem.Layout.Description.MaxSize = new Size(150, 0);
Me.RadRibbonBar1.RibbonBarElement.ApplicationMenuRightColumnWidth = 180
Me.LongNameFileMenuItem.Layout.Text.TextWrap = True
Me.LongNameFileMenuItem.Layout.Text.MaxSize = New Size(150, 0)
Me.UntitledFileMenuItem.Layout.Description.TextWrap = True
Me.UntitledFileMenuItem.Layout.Description.MaxSize = New Size(150, 0)
The result in this case will be:
Keyboard Support
The Application menu supports mnemonics and Arrows/Enter/Escape navigation.