Ribbon Controls Sample

Note

This sample runs only in Microsoft Office Excel 2007.

This sample demonstrates how to create a custom tab that appears on the Ribbon of a Microsoft Office Excel worksheet. This custom Ribbon demonstrates most of the controls available in the Office Ribbon Controls group of the Visual Studio Toolbox. For more information about using these controls, see Ribbon Designer.

Security noteSecurity Note:

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To run this sample

  1. Press F5.

  2. An Excel worksheet appears. The Ribbon of the worksheet displays a custom tab named Ribbon Control Sample.

    The Ribbon does not display any other tabs, because the StartFromScratch property of the custom Ribbon is set to true.

Requirements

This sample requires the following applications:

  • Visual Studio Tools for Office.

  • Microsoft Office Excel 2007.

Demonstrates

This sample demonstrates the following concepts:

  • Customizing a tab by using a Ribbon (Visual Designer) item template.

  • Hiding all built-in tabs and most commands on the Office menu, and displaying the customizations defined in this Ribbon item only.

  • Adding custom groups and controls to the Ribbon designer.

  • Handling the events of controls on the Ribbon.

  • Changing the properties of controls at run time.

  • Dynamically adding controls to a menu at run time.

  • Dynamically adding items to a gallery at run time.

  • Showing and hiding actions pane controls by using buttons on the Ribbon.

Working with Sheets Group

The following table describes the controls that appear in the Working with Sheets group of the custom Ribbon.

Control

Description

Action / Result

Show Actions Pane

A toggle button that appears pressed or not pressed.

Click Show Actions Pane.

An actions pane appears beside the worksheet.

Click Show Actions Pane a second time to hide the actions pane.

Face buttons

Three buttons contained in a button group. These buttons are added to the button group because they are related to one another. Buttons in a button group have a shiny appearance.

Click a face button.

Cell A1 displays a matching image.

Alignment

A split button. A split button is a button with a menu attached. The Alignment split button menu contains three buttons. The OfficeImageId property of the Alignment split button is set to the ID of a built-in Office alignment control.

Click Right Align, Left Align, or Center Align in the Alignment split button menu.

The text that appears in cell A3 is right justified, left justified, or centered.

Color

A gallery that presents an array of colored spheres from which you can select.

Click Color, and then select a color from the gallery.

A sphere that has the selected color appears in cell A6.

FormatChart

A drop-down control that contains a list of chart formats. Unlike a combo box, you cannot type a selection in a drop-down control.

Click Format Chart, and then select a format from the list.

The format of the chart that appears on the worksheet changes to match the format that you selected.

MRU Find

A combo box. You can either type or select a choice.

Click the MRU Find combo box, and then select text from the list.

- or -

In the MRU Find combo box, type any text and then press ENTER.

A message box appears that identifies the location of the text in the worksheet.

Building Dynamic Menu Group

The following table describes the controls that appear in the Building a Dynamic Menu group of the custom Ribbon.

Control

Description

Action / Result

Dynamic Menu

A menu. A menu is a drop-down list that can contain other Ribbon controls.

The Dynamic property of this menu is set to true. This enables the menu to be dynamically updated at run time.

Click Dynamic Menu to display a menu of controls.

CheckBox, DropDown, SubMenu, Gallery, Button, Separator

A set of check boxes. You can select or clear a check box to turn on or off an option.

Each check box represents a Ribbon control that you can add to Dynamic Menu.

Click a checkbox to add a Ribbon control to Dynamic Menu.

See Also

Tasks

Walkthrough: Creating a Custom Tab by Using the Ribbon Designer

Walkthrough: Updating the Controls on a Ribbon at Run Time

How to: Get Started Customizing the Ribbon

Concepts

Ribbon Overview

Other Resources

Samples and Walkthroughs (Office Development)