Click here to Skip to main content
15,922,630 members
Articles / Desktop Programming / Windows Forms

A Professional Ribbon You Will Use (Now with orb!)

Rate me:
Please Sign up or sign in to vote.
4.96/5 (573 votes)
12 Jun 2012Ms-PL6 min read 2.4M   141.8K   1.4K   630
A serious project on an Office-like Ribbon control

New: Read the guide for embedding the ribbon on the non-client area.

WinFormsRibbon/ribbon_0.4.008.jpg

Introduction

Because of the lack of good free Ribbon controls on the web, I decided to write one myself. I've analyzed previous work on ribbon-controls, including those on CodeProject. Unfortunately, most existent controls are merely bad tries. Why? well, some lack nice rendering, some lack resizing features, some lack almost everything. Of course, well developed Ribbon controls are available at a price. This ribbon is free.

Why not WPF? Well mainly, because I needed the Ribbon to add it to my existing WinForms applications. In my opinion (the short version) this is not a "no" to WPF, is just a "not yet". Anyway, you can host a WinForms control in WPF (See this link).

Some of the Design Goals

Performance - This ribbon is contained on a Control window, and every element inside of it is managed as a bunch of bounds inside the control, just as the ToolStrip control does. Although this is difficult to manage from the ribbon's inside code, this is a way to keep it at the best performed ribbon. Believe me, download the demo, run it and resize the window. It performs beautifully.

Consistency with Office's Ribbon - I read once about Jakob Nielsen saying that most users prefer that the programs they use look just like Word, Excel or PowerPoint. This is quite obvious, because people use this software every day. Providing visual consistency with the Office's ribbon is very important because of that, people already know what to expect and that's a usability advantage. I've tried to see that every element in the ribbon looks and behaves exactly like it does in the Office's ribbon.

Ease of use for programmers - The naming of components is consistent with most WinForms naming system, even more with the ToolStrip elements. Property, event and method names for similar elements are named just like in the ToolStrip technology items.

Designer support - I will be adding more and more designer support so you can manage the ribbon 100% from the designer. Give it a try.

I will be providing updates and fixes for bugs, as I discover them or you kindly let me know about them.

Using the Ribbon

The ribbon is located in the System.Windows.Forms namespace, just as every other control, I think it's annoying to use controls named as MyCoolFirm.MyCoolNameSpace.MyCoolSubNameSpace and so on (Please do that only for business objects).

You can add a reference to the compiled DLL: System.Windows.Forms.Ribbon.dll or you can directly copy the source files to a folder on your project. The code is currently designed so you can just copy the source files, it doesn't need any extra resources.

Hands on: Quick Guide

The ribbon is composed mainly by three kind of elements, the tabs, the panels on the tabs (other developers call them groups) and the items inside the panels.

WinFormsRibbon/ribbontab.gif

WinFormsRibbon/ribbonpanel.gif

WinFormsRibbon/ribbonitems.gif

These elements are represented by RibbonTab, RibbonPanel and RibbonItem types. RibbonItem is an abstract class that provides basic functionality for any item hosted on a RibbonPanel or on a RibbonDropDown.

You can add tabs from the smart tag of the Ribbon, you can add panels to the tab by selecting the tab and calling the "AddPanel" verb on the bottom part of the property grid.

The elements on the ribbon are resized according to the available space for the ribbon. This is a key feature of the ribbon. It tries to bring all possible commands to the screen by resizing them, instead of hiding them on an overflow button like the old ToolStrip.

I treat this as three kinds of sizes: Large, Medium and Compact. An additional size is used for panels because panels can be collapsed, and then they will adopt the Overflow size.

WinFormsRibbon/ribbonpanelsizes.gif

Note: There's no way to directly affect the bounds of the elements on the ribbon, the size will always be determined the layout engine inside the ribbon. In fact, the layout depends on two factors: the available horizontal space on the ribbon and the size modes on the items.

If there's no available space on the ribbon for a panel, panel will be collapsed. If all panels are collapsed and space is not available yet, a scroll button will appear so user can scroll the panels horizontally.

Click to enlarge image

Buttons

There's only one type of button: RibbonButton. It can be set to three styles:

WinFormsRibbon/ribbonbuttonstyles.gif

RibbonButton adds the SmallImage property so you can set the image shown when button is in medium or compact mode. Although it's not restricted by functionality, it's highly recommended to use just 32 x 32 pixels for Image property and 16 x 16 for SmallImage property. Results are unexpected when sizes are different.

Note: Use the DropDownItems property to add items to the dropdown of the button.

The appearance of the buttons vary through size modes.

ItemGroups

The buttons like those on the Font and Paragraph panels are RibbonButton buttons hosted inside a RibbonItemGroup group.

WinFormsRibbon/ribbonitemgroup.gif

Items added to RibbonItemGroup will always be measured and treated in compact size mode.

Important: If a RibbonPanel will host RibbonItemGroup objects, you must set the RibbonPanel.FlowsTo property to Right. The layout on those items are treated differently because groups flow as rows.

Lists

Lists are represented by RibbonButtonList and provide two collections: Buttons and DropDownItems. This is because the list can be scrolled on the ribbon and can dropdown more items. The dropdown of list supports resizing by a grip on the south east corner.

If you want the buttons on the list to be shown on the dropdown, you will have to explicitly add another list with those buttons to the DropDownItems property.

Separators

Separators are represented by RibbonButtonSeparator and provides the well known separator functionality. When in a dropdown, separators can actually contain text. When they contain text, they will be rendered differently.

WinFormsRibbon/ribbondropdown.gif

Tutorials

  • Getting Started With the Ribbon at ribbon.codeplex.com 

Known Bugs

  • Multiple dropdowns not managed OK 
  • Drawing of collapsed panels when mouse down

Things To Do

  • Contextual tabs
  • ToolTips
  • (OK) TextBox, ComboBox
  • Checkbox and NumericUpDown RibbonItems
  • Orb and Quickaccess tools
  • Vista clientarea docking
  • Keyboard quick access through Alt key
  • Font and Color selectors
  • Right to left orientation
  • Ribbon minimization

History

  • 8 May 2008 - Original post
  • 29 May 2008 - Update
    • Enabled property now working
    • Added RibbonTextBox - A regular textbox with label and image
    • Added RibbonComboBox - (Inherited from RibbonTextBox) Offers a dropdown
    • Added RibbonColorChooser - A button that shows a color bar. See property Color
  • 23 Feb 2009 - Update
    • Orb and orb menu with designer capabilities
    • Quick Access Toolbar added
    • Some bugs fixed
  • 1 May 2009 - Update 
    • Orb and Quick access embedded on non-client area
    • Popup menus fixed!
    • Lots of Event handlers supported
    • Minor bugs fixed

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Product Manager
United States United States
- I've been programming Windows and Web apps since 1997.
- My greatest concern nowadays is product, user interface, and usability.
- TypeScript / React expert

@geeksplainer

Comments and Discussions

 
GeneralRe: Thanks...but MDI not working Pin
jonnymoo13-May-09 14:12
jonnymoo13-May-09 14:12 
GeneralRe: Thanks...but MDI not working Pin
Baba Deep13-May-09 16:15
Baba Deep13-May-09 16:15 
GeneralRe: Thanks...but MDI not working Pin
cakecoong25-Aug-11 17:59
cakecoong25-Aug-11 17:59 
General"non-client-mode" not working, when ElementHost control is on form Pin
jus5-May-09 21:09
jus5-May-09 21:09 
GeneralBug with the new version (freezes my computer for 2-3 seconds and crashes) Pin
ken2k5-May-09 12:00
ken2k5-May-09 12:00 
GeneralRe: Bug with the new version (freezes my computer for 2-3 seconds and crashes) Pin
Gee.5-May-09 13:53
Gee.5-May-09 13:53 
GeneralRe: Bug with the new version (freezes my computer for 2-3 seconds and crashes) Pin
ken2k6-May-09 7:11
ken2k6-May-09 7:11 
GeneralRe: Bug with the new version (freezes my computer for 2-3 seconds and crashes) Pin
Gee.6-May-09 7:36
Gee.6-May-09 7:36 
Hi Ken

Wow - I wish I had your rig! Lol :p

It sounds like an issue with instantiation. You will often find that a heavy control will use several assemblies (the "using" clauses at the top of C# code) - and if these aren't in memory when an object is being instantiated, then they will have to be loaded before an object can finish being instantiated.

You should find that once the assemblies are loaded, subsequent instantiations of the object are a lot quicker.

Sadly, this isn't a C# or Windows only issue, even Apple's iPhone has to load resources into memory on initial use - its' just they disguise it with a static image of the final UI to trick people into thinking its' already loaded. In practice, Windows Mobile apps and iPhone apps are similarly paced.

I'm not suggesting that there isn't a bug - there are a few tricks that can be used to delay instantiation of helper objects, etc... - but I think that's one for the author! :p

Is it worth using a splash screen in the mean time (upon start-up) - then you can instantiate your main Form on a background thread. The trick here is to make sure that no heavy object construction is done in the Form's Shown event.

I hope that helps!

Gee

GeneralRe: Bug with the new version (freezes my computer for 2-3 seconds and crashes) Pin
ken2k6-May-09 12:16
ken2k6-May-09 12:16 
GeneralRe: Bug with the new version (freezes my computer for 2-3 seconds and crashes) Pin
JoanComasFdz2-Jun-09 0:04
JoanComasFdz2-Jun-09 0:04 
GeneralRe: Bug with the new version (freezes my computer for 2-3 seconds and crashes) Pin
jaimi2-Jun-09 5:02
jaimi2-Jun-09 5:02 
GeneralRe: Bug with the new version (freezes my computer for 2-3 seconds and crashes) Pin
jaimi2-Jun-09 5:18
jaimi2-Jun-09 5:18 
GeneralThanks, AGAIN! Pin
pimb25-May-09 4:59
pimb25-May-09 4:59 
GeneralBug Feedback on new version Pin
Gee.5-May-09 0:28
Gee.5-May-09 0:28 
GeneralVista Ribbon Form Pin
Muneer Safi4-May-09 23:09
Muneer Safi4-May-09 23:09 
GeneralRe: Vista Ribbon Form Pin
Vladimir Svyatski7-May-09 7:53
professionalVladimir Svyatski7-May-09 7:53 
QuestionCPU eating? Pin
I'm Chris3-May-09 22:37
professionalI'm Chris3-May-09 22:37 
Generalnot correctly render non-client area Pin
Huisheng Chen3-May-09 19:10
Huisheng Chen3-May-09 19:10 
QuestionHow to enable auto hide like functionality Pin
AKDM27-Apr-09 5:35
AKDM27-Apr-09 5:35 
GeneralOrb Dropdownmenu problem Pin
Fco. Javier Marin19-Apr-09 13:19
Fco. Javier Marin19-Apr-09 13:19 
GeneralSome More Feature Required to make perfect Ribbon Pin
pcm_it15-Apr-09 23:30
pcm_it15-Apr-09 23:30 
GeneralSubmenus Pin
Gee.15-Apr-09 12:32
Gee.15-Apr-09 12:32 
QuestionHow to add controls to the ribbon? [modified] Pin
Jimmy Bobby14-Apr-09 17:36
Jimmy Bobby14-Apr-09 17:36 
AnswerRe: How to add controls to the ribbon? Pin
Lars2129-Sep-09 1:31
Lars2129-Sep-09 1:31 
GeneralRe: How to add controls to the ribbon? Pin
Lars2129-Sep-09 2:05
Lars2129-Sep-09 2:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.