windowsforms-devexpress-dot-xtrabars-dot-ribbon-99178267.md
Allows you to create a Ribbon toolbar with commands grouped into categories, pages and page groups.
Namespace : DevExpress.XtraBars.Ribbon
Assembly : DevExpress.XtraBars.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXLicenseWinForms]
public class RibbonControl :
ControlBase,
IBarObject,
IXtraSerializable,
IXtraSerializableLayout,
ICustomBarControl,
IExtenderProvider,
IDXMenuManager,
IDXDropDownMenuManager,
ISupportXtraAnimation,
IToolTipControlClientEx,
IToolTipControlClient,
IEditorBackgroundProvider,
IBackstageViewOwner,
ISupportInitialize,
ISupportGlassRegions,
IGestureClient,
ISupportAdornerUIRibbon,
ISupportAdornerUIManager,
IWin32Window,
IUpdateAdornerUI,
IPopupControlOwner,
ICommandOwnerControl,
ISupportDXSkinColors,
ISupportImageDragDrop,
IXtraSupportForceInitialize,
IScaleDpiProvider,
ISupportSingleTapToShowKeyboard,
ITransparentBackgroundManagerEx,
IKeyboardSelectionClient
<DXLicenseWinForms>
Public Class RibbonControl
Inherits ControlBase
Implements IBarObject,
IXtraSerializable,
IXtraSerializableLayout,
ICustomBarControl,
IExtenderProvider,
IDXMenuManager,
IDXDropDownMenuManager,
ISupportXtraAnimation,
IToolTipControlClientEx,
IToolTipControlClient,
IEditorBackgroundProvider,
IBackstageViewOwner,
ISupportInitialize,
ISupportGlassRegions,
IGestureClient,
ISupportAdornerUIRibbon,
ISupportAdornerUIManager,
IWin32Window,
IUpdateAdornerUI,
IPopupControlOwner,
ICommandOwnerControl,
ISupportDXSkinColors,
ISupportImageDragDrop,
IXtraSupportForceInitialize,
IScaleDpiProvider,
ISupportSingleTapToShowKeyboard,
ITransparentBackgroundManagerEx,
IKeyboardSelectionClient
The following members return RibbonControl objects:
Show 24 links
The Ribbon Control displays various commands, generally represented as buttons, by categorizing them into pages and page groups. The following screenshot shows a sample Ribbon Control which consists of two pages (“Home” and “View”). The first page contains three groups (“New”, “Actions”, and “Quick Letter”), and each group contains specific commands.
Structurally, a Ribbon Control contains one or more pages which are displayed as tabs. The control’s pages, which are represented by RibbonPage objects, can be accessed with the RibbonControl.Pages collection. You can use the RibbonControl.Pages property to add, remove and access specific pages and customize their settings.
A Ribbon page is divided into groups which display specific commands. Page groups (RibbonPageGroup class objects) can be accessed from the RibbonPage.Groups property.
Each page group can display various elements: buttons, static text, submenus, editors, etc. To add a specific element to the group, create a corresponding bar item and add it to the RibbonPageGroup.ItemLinks collection. For information on bar items and bar item links, refer to Items and Item Links.
Note
If you create bar items in code, ensure the following:
The following list shows the correct ways to create bar items while adding them to the RibbonControl.Items collection.
The BarItem.Id properties can be initialized with the BarManager.GetNewItemId method accessible from the RibbonControl.Manager object.
The Quick Access Toolbar displayed by default at the top of the Ribbon Control allows you to display the most used commands. Use the RibbonControl.ToolbarLocation property to control the toolbar’s position and visibility. The RibbonControl.Toolbar property permits you to access the toolbar and customize its contents.
For more information on Ribbon elements, see Ribbon Control.
When you place a RibbonControl on a form at design time, all controls publish the PopupContextMenu extender property (its caption in the Properties window looks like ‘PopupContextMenu on ribbonControl1’). You can use this property to assign a PopupMenu or RadialMenu menu for this control. This menu will be displayed when right-clicking the control at runtime.
To assign a popup menu for a control in code, use the RibbonControl.SetPopupContextMenu method.
Note
Specific complex controls such as Grid Control and Tree List do not publish the PopupContextMenu property, as these controls support different context menus for different visual elements. See the help documentation on these products to learn how to work with context menus in these controls.
Note
Using regular bars (a BarManager component) and a RibbonControl within the same form/user control is not recommended, as the Bar Manager and Ribbon Control components may conflict with each other. Use either a Bar Manager or a Ribbon Control within a single form/user control.
This example creates DevExpress WinForms RibbonControl and RibbonStatusBar:
RibbonControl contains the “Home” page, “File” and “Print” groups, and four commands (bar items).RibbonStatusBar displays the “Print” command. The “Print” command is aligned to the right.The following animation shows the result:
Prerequisites
In this example, the SvgImageCollection was created and populated with SVG images at design-time.
Note
When creating the Ribbon UI in code, ensure that the following requirements are met:
using System.Windows.Forms;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars;
using DevExpress.XtraEditors;
namespace DXApplication
{
public partial class Form1 : XtraForm
{
public Form1()
{
InitializeComponent();
// Create the DevExpress RibbonControl
RibbonControl ribbon = new RibbonControl();
this.Controls.Add(ribbon);
/* Assign the SVG image collection to display images/icons within bar items.
* In this example, the svgImageCollection1 was created and populated with SVG images at design-time.
*/
ribbon.Images = svgImageCollection1;
// Create a Ribbon page.
RibbonPage pageHome = new RibbonPage("Home");
ribbon.Pages.Add(pageHome);
// Create a Ribbon page group.
RibbonPageGroup groupFile = new RibbonPageGroup("File");
pageHome.Groups.Add(groupFile);
// Create another Ribbon page group.
RibbonPageGroup groupPrint = new RibbonPageGroup("Print");
pageHome.Groups.Add(groupPrint);
// Create button items and add them to the 'File' group.
BarButtonItem itemNew = ribbon.Items.CreateButton("New");
// Ensures correct runtime layout (de)serialization.
itemNew.Id = ribbon.Manager.GetNewItemId();
// Specifies the image.
itemNew.ImageOptions.SvgImage = svgImageCollection1["new"];
itemNew.RibbonStyle = RibbonItemStyles.Large;
itemNew.ItemClick += ItemClick;
BarButtonItem itemOpen = ribbon.Items.CreateButton("Open");
itemOpen.Id = ribbon.Manager.GetNewItemId();
itemOpen.RibbonStyle = RibbonItemStyles.Large;
itemOpen.ImageOptions.SvgImage = svgImageCollection1["open"];
itemOpen.ItemClick += ItemClick;
groupFile.ItemLinks.AddRange(new BarItem[] { itemNew, itemOpen });
/* Create a button item using its constructor and add the button item to the 'Print' group.
* The constructor automatically adds the new item to the RibbonControl's Items collection.
*/
BarButtonItem itemPrint = new BarButtonItem(ribbon.Manager, "Print")
{
Id = ribbon.Manager.GetNewItemId(),
RibbonStyle = RibbonItemStyles.Large
};
itemPrint.ImageOptions.SvgImage = svgImageCollection1["print"];
itemPrint.ItemClick += ItemClick;
// Create a button item using the default constructor.
BarButtonItem itemPreview = new BarButtonItem()
{
Caption = "Preview",
RibbonStyle = RibbonItemStyles.Large,
Id = ribbon.Manager.GetNewItemId(),
};
itemPreview.ImageOptions.SvgImage = svgImageCollection1["preview"];
itemPreview.ItemClick += ItemClick;
// Add the 'Preview' item to the RibbonControl's Items collection.
ribbon.Items.Add(itemPreview);
groupPrint.ItemLinks.AddRange(new BarItem[] { itemPrint, itemPreview });
// Create a status bar with the 'Print' command.
RibbonStatusBar ribbonStatusBar = new RibbonStatusBar(ribbon)
{
Parent = this
};
BarItemLink linkPrint = ribbonStatusBar.ItemLinks.Add(itemPrint);
linkPrint.UserRibbonStyle = RibbonItemStyles.SmallWithoutText;
linkPrint.UserAlignment = BarItemLinkAlignment.Right;
}
void ItemClick(object sender, ItemClickEventArgs e)
{
XtraMessageBox.Show(string.Format("{0} command clicked.", e.Item.Caption), "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
Imports System.Windows.Forms
Imports DevExpress.XtraBars.Ribbon
Imports DevExpress.XtraBars
Imports DevExpress.XtraEditors
Namespace DXApplication
Partial Public Class Form1
Inherits XtraForm
Public Sub New()
InitializeComponent()
' Create the DevExpress RibbonControl
Dim ribbon As New RibbonControl()
Me.Controls.Add(ribbon)
' Assign the SVG image collection to display images/icons within bar items.
' * In this example, the svgImageCollection1 was created and populated with SVG images at design-time.
'
ribbon.Images = svgImageCollection1
' Create a Ribbon page.
Dim pageHome As New RibbonPage("Home")
ribbon.Pages.Add(pageHome)
' Create a Ribbon page group.
Dim groupFile As New RibbonPageGroup("File")
pageHome.Groups.Add(groupFile)
' Create another Ribbon page group.
Dim groupPrint As New RibbonPageGroup("Print")
pageHome.Groups.Add(groupPrint)
' Create button items and add them to the 'File' group.
Dim itemNew As BarButtonItem = ribbon.Items.CreateButton("New")
' Ensures correct runtime layout (de)serialization.
itemNew.Id = ribbon.Manager.GetNewItemId()
' Specifies the image.
itemNew.ImageOptions.SvgImage = svgImageCollection1("new")
itemNew.RibbonStyle = RibbonItemStyles.Large
AddHandler itemNew.ItemClick, AddressOf ItemClick
Dim itemOpen As BarButtonItem = ribbon.Items.CreateButton("Open")
itemOpen.Id = ribbon.Manager.GetNewItemId()
itemOpen.RibbonStyle = RibbonItemStyles.Large
itemOpen.ImageOptions.SvgImage = svgImageCollection1("open")
AddHandler itemOpen.ItemClick, AddressOf ItemClick
groupFile.ItemLinks.AddRange(New BarItem() { itemNew, itemOpen })
' Create a button item using its constructor and add the button item to the 'Print' group.
' * The constructor automatically adds the new item to the RibbonControl's Items collection.
'
Dim itemPrint As New BarButtonItem(ribbon.Manager, "Print") With {
.Id = ribbon.Manager.GetNewItemId(),
.RibbonStyle = RibbonItemStyles.Large
}
itemPrint.ImageOptions.SvgImage = svgImageCollection1("print")
AddHandler itemPrint.ItemClick, AddressOf ItemClick
' Create a button item using the default constructor.
Dim itemPreview As New BarButtonItem() With {
.Caption = "Preview",
.RibbonStyle = RibbonItemStyles.Large,
.Id = ribbon.Manager.GetNewItemId()
}
itemPreview.ImageOptions.SvgImage = svgImageCollection1("preview")
AddHandler itemPreview.ItemClick, AddressOf ItemClick
' Add the 'Preview' item to the RibbonControl's Items collection.
ribbon.Items.Add(itemPreview)
groupPrint.ItemLinks.AddRange(New BarItem() { itemPrint, itemPreview })
' Create a status bar with the 'Print' command.
Dim ribbonStatusBar As New RibbonStatusBar(ribbon) With {.Parent = Me}
Dim linkPrint As BarItemLink = ribbonStatusBar.ItemLinks.Add(itemPrint)
linkPrint.UserRibbonStyle = RibbonItemStyles.SmallWithoutText
linkPrint.UserAlignment = BarItemLinkAlignment.Right
End Sub
Private Sub ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
XtraMessageBox.Show(String.Format("{0} command clicked.", e.Item.Caption), "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
End Class
End Namespace
Object MarshalByRefObject Component Control DevExpress.XtraEditors.XtraControl ControlBase RibbonControl
See Also