The RibbonHost Control is a special Ribbon control that allows a custom (non-Ribbon) control to be displayed on the Ribbon. This allow the user to extend the functionality of the Ribbon.
A RibbonHost contain may be inserted anywhere a RibbonItem can, though depending on the type of control, it may not display correctly.
To add a custom control, for example on the Ribbon directly:
- Add your custom control (from the toolbox) to somewhere on your form. Don't worry, it will disappear at runtime.
- Insert a RibbonHost control onto a Panel as you would a RibbonButton.
- In the properties of the RibbonHost, change the HostedControl property to the name of your custom control:
- Run your project and confirm that the control appears in the correct location.
- Hook into the events of your custom control as if it were not hosted on the RibbonHost.
There is one RibbonHost event that is fired when the Ribbon changes size. The event details the new SizeMode of the your control (Large, Compact, etc.). The Ribbon does not know how you want to handle the change, if at all, so you must provide the programming
for such changes. For example, you may want your control to be 100 pixels wide in Large mode, 50 pixels wide in Medium mode and invisible in Compact and Small mode.
Below is an example of a split button dropdown containing two buttons and a RibbonHost control hosting a
Below is an example of a MonthCalendar control in a ComboBox using a RibbonHost located in the ComboBox list:
Below is an example of a Progress Bar control on the Ribbon:
Note that as error ("null reference error with hosted object" or similar) has been seen caused by the order of controls in the designer. The RibbonHost HostedControl is set to an object that has not yet been defined. In this case, the current work
around is to set the HostedControl on form load instead of in the designer.