Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Collapse]Ribbon, Bars and Menu
   [Expand]Bars
   [Expand]Ribbon
   [Expand]Popup Menus
    Radial Menu
   [Expand]Common Features
   [Collapse]Examples
    [Expand]Bars
    [Collapse]Ribbon
      How to: Add Bar Items to the Tab Header Area
      How to: Apply the Button Group layout to a set of bar item links
      How to: Create a multi-level BackstageView Control
      How to: Create a RibbonControl in Code
      How to: Create an In-Ribbon Gallery
      How to: Create Contextual Tabs
      How to: Custom Draw Gallery Items
      How to: Customize a RibbonControl's Customization Menu
      How to: Get Visible and All Ribbon Pages
      How to: Merge Ribbon Controls
      How to: Merge RibbonStatusBar Objects
    [Expand]Popup Menus
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Create a RibbonControl in Code

This example demonstrates how to create a RibbonControl with one page ("Home") and two page groups ("File" and "File 2").

Ribbon commands are called bar items, as they are all derived from the BarItem class. This example creates three bar items - the Open, Close and Print buttons, encapsulated by the BarButtonItem objects. The Close and Print buttons are only added to the first group, while the Open button is added to both of the groups.

When bar items are created in code, ensure the following:
  1. All bar items are added to the RibbonControl.Items collection.

    This example demonstrates three ways of creating bar items while adding them to the RibbonControl.Items collection.

  2. All bar items have their BarItem.Id properties initialized to unique values. This ensures correct functioning of the bar item (de)serialization mechanism.

    The BarItem.Id properties can be initialized with the BarManager.GetNewItemId method accessible from the RibbonControl.Manager object. See the code below.

How would you rate this topic?​​​​​​​