Ribbon for WinForms | ComponentOne
In This Topic
    Quick Start
    In This Topic

    The following quick start guide will take you through the basics of Ribbon control and its design customizations. You can add tabs, groups and items to the groups. By the end of this section, you will be able to create a simple text editor with the Ribbon user interface.

    To create a simple WinForms application in .NET 4.5.2 for Ribbon control, complete the following steps: 

    1. Create a new Windows Forms application.
    2. Drag and drop the C1Ribbon control to your form.The Ribbon control is positioned at the top of the form. A tab and group gets added to the Ribbon control in advance.

      The image shows a ribbon control in application with tab.
    3. Add the RichTextBox control from the Toolbox to your form. Set its Dock property to Fill.
    4. To add a new tab, click the C1Ribbon control to enable its floating toolbar. Click the Actions button and select Add Tab from the list of actions. Whenever you add a new tab, a group is already added to it.
    5. Rename the tabs as 'Home' and 'Insert'. This can be done by in-place text editing by double clicking the tab. You can also add text from the Text Settings in floating toolbar or by editing the Text property in the Properties window.

      The image shows a ribbon control in application with group and tab.
    6. To add a new group, click the 'Home' Tab to enable its floating toolbar. Click the Actions button and select Add Group from the list of actions.

      The image shows a menu open in ribbon control
    7. Rename the groups as 'Font' and 'Color' either by double clicking on it or by editing the Text property from the Properties window.

      The image shows ribbon with tab and group.
    8. To add an item to the group, click the 'Font' group to enable its floating toolbar. Click the Actions button and Select Add Font ComboBox from the list of actions.
      The image shows a big menu open in ribbon control.
    9. Enter the placeholder text 'Select a Font' in the Font ComboBox either by clicking on it or editing the Text property from the Properties window.
      The image shows groups and tabs in ribbon, with a combobox.
    10. Similarly, select Add ColorPicker from the list of actions of 'Color' group to add it as an item.

      A snapshot of colorpicker in ribbon control.
    11. The Windows Form can be converted to a Ribbon Form by switching to the code view and replacing the following:
      Copy Code
      partial class Form1 : Form
      Copy Code
      Partial Class Form1
          Inherits System.Windows.Forms.Form
      End Class


      Copy Code
      partial class Form1 : C1RibbonForm
      Copy Code
      Partial Class Form1
          Inherits C1.Win.C1Ribbon.C1RibbonForm
      End Class
    The basic difference between the Windows form and the Ribbon Form is that in the Ribbon form, the title bar of the Windows Form is omitted and the title bar of the Ribbon Form comes into existence.

    Run the application and observe the Ribbon Form generated in the following image. The Ribbon Form contains tabs, groups and FontComboBox and ColorPicker as items in the Group. Similarly, you can add other items from the group item list such as DatePicker, Gallery, Label, CheckBox, ToggleButton, TextBox etc.

    A snapshot of windowforms application with ribbon control, depicting tabs, groups, colorpicker and combobox.

    To create a simple WinForms application in .NET 6 for Ribbon control, complete the following steps: 
    1. Create a new Windows Forms application.

    2. Switch to code editor and initialize the C1Ribbon object.

      Copy Code
      C1Ribbon customRibbon;
    3. Initialize the Ribbon control and add the control to the Form.

      Copy Code
      // Initialize the Ribbon control
      customRibbon = new C1Ribbon();
      // Add the ribbon control to the Form
    4. Create an instance of RibbonTab class and add the 'Home' tab to the Ribbon control using the Add method of RibbonTabCollection class.

      Copy Code
      // Create and add the "Home" tab
      RibbonTab homeTab = new RibbonTab();
      homeTab.Text = "Home";
    5. Create an instance of RibbonGroup class, assign it the name 'Font' and add it to the Home tab using the Add method of RibbonGroupCollection class.

      Copy Code
      // Add a group named "Font" to the "Home" tab
      RibbonGroup fontStyle = new RibbonGroup();
      fontStyle.Text = "Font";
    6. Create Quick Access Toolbar in the Ribbon control using the Qat property of C1Ribbon class, and add items to the Quick Access Toolbar using the Items property of RibbonQat class and Add method of RibbonItemCollectionBase class.

      Copy Code
      // Add Items to the quick access toolbar 
      Image openImage = Image.FromFile(@"images\open.png");
      customRibbon.Qat.Items.Add(new RibbonButton("Open", openImage));
      Image undoImage = Image.FromFile(@"images\undo.png");
      customRibbon.Qat.Items.Add(new RibbonButton("Undo", undoImage));
      Image redoImage = Image.FromFile(@"images\redo.png");
      customRibbon.Qat.Items.Add(new RibbonButton("Repeat", redoImage));
    7. Create items to be added in application menu. Add them to the right and left panel of the Application Menu using ApplicationMenu property of C1Ribbon class.

      Copy Code
      // Create Items to be added in the default Application Menu
      RibbonButton openButton = new RibbonButton("Open", Image.FromFile(@"images\open-file-icon.png"));
      RibbonButton saveButton = new RibbonButton("Save", Image.FromFile(@"images\save-file-icon.png"));
      RibbonButton closeButton = new RibbonButton("Close", Image.FromFile(@"images\close.png"));
      RibbonButton printButton = new RibbonButton("Print", Image.FromFile(@"images\print.png"));
      RibbonButton previewButton = new RibbonButton("Preview", Image.FromFile(@"images\preview.png"));           
      RibbonListItem print = new RibbonListItem(printButton);
      RibbonListItem preview = new RibbonListItem(previewButton);
      // Add image Icon for ApplicationMenu
      C1BitmapIcon c1Bitmap1 = new C1BitmapIcon();
      c1Bitmap1.Source = Image.FromFile(@"images\application_menu.png");
      c1Bitmap1.Size = new Size(20, 20);
      // Add Application Menu items
    8. Create items to be added in configuration toolbar. Add the items using ConfigToolBar property of C1Ribbon class.

      Copy Code
      //Create Items to be added in the default ConfigToolbar
      RibbonButton cutButton = new RibbonButton("Cut", Image.FromFile(@"images\cut.png"));
      RibbonButton copyButton = new RibbonButton("Copy", Image.FromFile(@"images\copy.png"));
      RibbonButton pasteButton = new RibbonButton("Paste", Image.FromFile(@"images\paste.png"));            
      // Add ConfigToolbar items
    9. Add a new tab 'Format' and new 'Clipboard' group. Add items like button, checkbox, fontcombobox, colorpicker, toggle button and separator to the new tab and group.

      Copy Code
      // Add items like button, checkbox, fontcombobox, colorpicker, toggle button and separator
      //Create a new Tab
      RibbonTab format = new RibbonTab();
      format.Text = "Format";
      //Adding a Group
      RibbonGroup formatGroup = new RibbonGroup();
      formatGroup.Text = "Clipboard";
      // Add ribbon button 
      RibbonButton clearButton = new RibbonButton("Clear Format", Image.FromFile(@"images\clearformat.png"));
      clearButton.ToolTip = "Clear All Formatting";
      // Add CheckBox button ribbon item
      RibbonCheckBox reminderCheckBox = new RibbonCheckBox();
      reminderCheckBox.IconSet.Add(new C1BitmapIcon(null, new Size(20, 20), Color.Transparent, Image.FromFile(@"images\reminder.png")));
      reminderCheckBox.Text = "Reminder";
      //Add RibbonFontComboBox
      RibbonFontComboBox fontComboBox = new RibbonFontComboBox();
      fontComboBox.ToolTip = "Font";
      fontComboBox.Text = "Select a font";
      //Add RibbonSeparator
      RibbonSeparator separator = new RibbonSeparator();
      //Add RibbonColorPicker
      RibbonColorPicker colorPicker = new RibbonColorPicker(null, Image.FromFile(@"images\fontcolor.png"));
      colorPicker.ToolTip = "Color Picker";
      // Add toggle button 
      RibbonToggleButton leftAlign = new RibbonToggleButton(Image.FromFile(@"images\align_left.png"));
      leftAlign.ToolTip = "Align your content with left margin.";
    10. Add items like datepicker, gallery, label and menu to another tab and group.

      Copy Code
      // Add items like datepicker, gallery, label and menu
      // Create a new Tab 'Tools'
      RibbonTab tool = new RibbonTab();
      tool.Text = "Tools";
      // Add Editor group to Tools tab
      RibbonGroup toolGroup = new RibbonGroup();
      toolGroup.Text = "Editor";
      // Add DatePicker ribbon item
      RibbonDatePicker datePicker = new RibbonDatePicker();
      datePicker.Format = "yyyy/MM/dd";
      // Add RibbonGallery ribbon item
      RibbonGallery ribbonGallery = new RibbonGallery();
      ribbonGallery.ToolTip = "Select a shape";
      RibbonGalleryItem ribbonGallery1 = new RibbonGalleryItem("Rectangle", Image.FromFile(@"images\rect.png"));
      RibbonGalleryItem ribbonGallery2 = new RibbonGalleryItem("Circle", Image.FromFile(@"images\circle.png"));
      RibbonGalleryItem ribbonGallery3 = new RibbonGalleryItem("Triangle", Image.FromFile(@"images\triangle.png"));
      RibbonGalleryItem ribbonGallery4 = new RibbonGalleryItem("Hexagon", Image.FromFile(@"images\hexagon.png"));
      // Add a Label ribbon item
      RibbonLabel ribbonLabel = new RibbonLabel("Feedback", Image.FromFile(@"images\feedback.png"));
      // Add RibbonMenu ribbon item
      RibbonMenu ribbonMenu = new RibbonMenu();
      ribbonMenu.Text = "Edit";
      RibbonButton buttonCut = new RibbonButton("Cut", Image.FromFile(@"images\cut.png"));
      RibbonButton buttonCopy = new RibbonButton("Copy", Image.FromFile(@"images\copy.png"));
      RibbonButton buttonPaste = new RibbonButton("Paste", Image.FromFile(@"images\paste.png"));
      RibbonSeparator separatoritem = new RibbonSeparator();
      RibbonColorPicker colorpicker = new RibbonColorPicker("Color Picker", Image.FromFile(@"images\fontcolor.png"));
      RibbonLabel label = new RibbonLabel("Select Color");
      RibbonColorPickerItem colorItem = new RibbonColorPickerItem();
    11. Add more items like Numeric box, progress bar, splitbutton, textbox, timepicker, toolbar and trackbar.

      Copy Code
      // Add more items like Numeric box, progress bar, splitbutton, textbox, timepicker, toolbar and trackbar
      // Add Styles group to Tools tab
      RibbonGroup stylesGroup = new RibbonGroup();
      stylesGroup.Text = "Styles";
      // Add Numeric Box ribbon item
      RibbonNumericBox numericBox = new RibbonNumericBox();
      numericBox.Maximum = 10;
      numericBox.Minimum = 1;
      numericBox.ToolTip = "Select a number";
      numericBox.Label = "Number Box";
      // Add Progress Bar ribbon item
      RibbonProgressBar progressBar = new RibbonProgressBar();
      progressBar.Minimum = 0;
      progressBar.Maximum = 100;
      progressBar.Value = 30;
      // Add Separator ribbon item
      RibbonSeparator separatorItem = new RibbonSeparator();
      // Add Ribbon Split Button
      RibbonSplitButton splitButton = new RibbonSplitButton("Views");
      RibbonButton printLayout = new RibbonButton("Print Layout", Image.FromFile(@"images\printlayout.png"));
      RibbonButton fullScreenLayout = new RibbonButton("Full Screen Reading", Image.FromFile(@"images\fullscreen.png"));
      RibbonButton webLayout = new RibbonButton("Web Layout", Image.FromFile(@"images\weblayout.png"));
      // Add Ribbon TextBox
      RibbonTextBox textBox = new RibbonTextBox();
      textBox.Text = "Write Text";
      // Add TimePicker
      RibbonTimePicker timePicker = new RibbonTimePicker();
      timePicker.Label = "Select Time:";
      // Add Ribbon Toolbar
      RibbonToolBar ribbonToolBar = new RibbonToolBar();
      RibbonButton boldButton = new RibbonButton(Image.FromFile(@"images\bold.png"));
      RibbonButton italicButton = new RibbonButton(Image.FromFile(@"images\italic.png"));
      RibbonButton underlineButton = new RibbonButton(Image.FromFile(@"images\underline.png"));
      // Add TrackBar 
      RibbonTrackBar trackBar = new RibbonTrackBar();
      trackBar.Minimum = 10;
      trackBar.Maximum = 100;
      trackBar.Value = 30;
      trackBar.TickFrequency = 10;

      Note that the Ribbon control provides dedicated class for each item in the ribbon, such as RibbonButtonRibbonCheckBoxRibbonFontComboBoxRibbonSeparatorRibbonColorPickerRibbonToggleButtonRibbonDatePickerRibbonGalleryRibbonLabelRibbonMenuRibbonNumericBoxRibbonProgressBarRibbonSplitButtonRibbonTextBoxRibbonTimePickerRibbonToolbarRibbonTrackBar classes.

    12. Ribbon control also allows the user to add a hosted control in the ribbon using the RibbonControlHost class. For this, the user has to create a new TextBoxHost class that inherits the RibbonControlHost element, and then initialize RibbonControlHost object in the form and add it to the ribbon group.

      Copy Code
      // Add Control Host
      RibbonControlHost textboxHost = new RibbonControlHost();
      textboxHost = new WinFormsRibbonQuickStart.TextBoxHost();
      Copy Code
      // Create a new TextBoxHost class
      public class TextBoxHost : C1.Win.Ribbon.RibbonControlHost
          public TextBoxHost() : base(new System.Windows.Forms.TextBox())
              base.Text = "Sample text";

      Run the application and observe the ribbon control with tabs, groups and ribbon items.

      A snapshot of window forms application with ribbon control depicting tabs, groups and numerous items such as combobox, labels, datepicker etc., to name a few.

      Note: WinForms .NET 6 Edition does not include rich design-time support yet. We will enhance it in future releases.