Share via


RibbonButton Interface

Represents a button on a custom Ribbon.

Namespace:  Microsoft.Office.Tools.Ribbon
Assembly:  Microsoft.Office.Tools.Common (in Microsoft.Office.Tools.Common.dll)

Syntax

'Declaration
<GuidAttribute("b57e6217-33f2-46bf-9625-c313526de60c")> _
Public Interface RibbonButton _
    Inherits RibbonControl, RibbonComponent, IComponent, IDisposable
[GuidAttribute("b57e6217-33f2-46bf-9625-c313526de60c")]
public interface RibbonButton : RibbonControl, 
    RibbonComponent, IComponent, IDisposable

The RibbonButton type exposes the following members.

Properties

  Name Description
Public property ControlSize Gets or sets the size of the button.
Public property Description Gets or sets the text that appears on this button in a menu when the ItemSize property of the menu is set to Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge.
Public property Enabled Gets or sets a value that indicates whether this RibbonControl is enabled. (Inherited from RibbonControl.)
Public property Id Gets a string that Microsoft Office uses to identify this RibbonControl object. (Inherited from RibbonControl.)
Public property Image Gets or sets the image that is displayed on the button.
Public property ImageName Gets or sets the name that you can use to identify the button in the LoadImage event handler.
Public property KeyTip Gets or sets the keyboard shortcut of the button.
Public property Label Gets or sets the text that is displayed on the button.
Public property Name Gets or sets the name of this RibbonComponent. (Inherited from RibbonComponent.)
Public property OfficeImageId Gets or sets the image to display on the button, if you want to use a built-in Microsoft Office icon.
Public property Parent Gets a RibbonComponent that represents the parent of this RibbonComponent. (Inherited from RibbonComponent.)
Public property Position Gets or sets the position of the button, if the button is on the Microsoft Office Menu.
Public property Ribbon Gets the top-level Ribbon object that contains the control hierarchy. (Inherited from RibbonComponent.)
Public property RibbonUI Infrastructure. Gets the IRibbonUI instance that is provided by the Microsoft Office application to the Ribbon extensibility code. (Inherited from RibbonComponent.)
Public property ScreenTip Gets or sets tooltip text that appears when the user moves the pointer over the button.
Public property ShowImage Gets or sets a value that indicates whether the image that is associated with the button is visible.
Public property ShowLabel Gets or sets a value that indicates whether the label for the button is visible.
Public property Site Gets or sets the ISite associated with the IComponent. (Inherited from IComponent.)
Public property SuperTip Gets or sets multiline tip text that appears when the user moves the pointer over the button.
Public property Tag Gets or sets application-specific data that is associated with this RibbonComponent. (Inherited from RibbonComponent.)
Public property Visible Gets or sets a value that indicates whether this RibbonControl is visible. (Inherited from RibbonControl.)

Top

Methods

  Name Description
Public method Dispose Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.)
Public method PerformDynamicLayout Calls the Microsoft.Office.Core.IRibbonUI.InvalidateControl method of the parent control if the RibbonComponent has a dynamic parent, such as a dynamic menu, and layout is not suspended. (Inherited from RibbonComponent.)
Public method PerformLayout Calls Microsoft.Office.Core.IRibbonUI.InvalidateControl if the RibbonComponent has a parent and layout is not suspended. (Inherited from RibbonComponent.)
Public method ResumeLayout() Reverses the effect of the SuspendLayout method. (Inherited from RibbonComponent.)
Public method ResumeLayout(Boolean) Reverses the effect of the SuspendLayout method. (Inherited from RibbonComponent.)
Public method SuspendLayout Prevents the Microsoft Office application from refreshing the state of controls on the Ribbon. (Inherited from RibbonComponent.)

Top

Events

  Name Description
Public event Click Occurs when the user clicks the button.
Public event Disposed Represents the method that handles the Disposed event of a component. (Inherited from IComponent.)

Top

Remarks

Visual Studio creates an instance of a class that implements the RibbonButton interface when you drag a Button control from the Office Ribbon Controls tab of the Toolbox onto the Ribbon Designer.

You can also create an instance of this control at run time and add it to a dynamic menu. A menu is dynamic if you set its Dynamic property to true.

Some properties of this control can be set only before the Ribbon is loaded into the Office application or before the control is added to a dynamic menu at run time. For information about setting these properties, see Ribbon Object Model Overview.

You can create a RibbonButton at run time by using the CreateRibbonButton method of the RibbonFactory object.

There are two ways to access the RibbonFactory object:

  • By using the Factory property of the Ribbon class. Use this approach from code in your Ribbon class.

  • By using the Globals.Factory.GetRibbonFactory method. Use this approach from code outside your Ribbon class.

Common Tasks

The following table lists members that are useful for common tasks.

Task

Member

At run time, add a button to a menu that has its Dynamic property set to true.

Create an instance of a class that implements the RibbonButton interface by using the CreateRibbonButton

method of the RibbonFactory class. For more information, see Global Access to Objects in Office Projects.

Add the instance to the menu's Items collection.

Change the size of the button.

Set ControlSize to the value you want. For example, for a large button, set it to Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge.

Display an image on the button.

There are three ways to display an image:

  • Use the Image property. This property gives the most control.

  • Set OfficeImageId to the ID of a built-in Microsoft Office image that you want to display as the icon for the button.

  • Use the ImageName property along with the LoadImage event. This property gives some performance benefits.

Disable or hide buttons.

To disable a button, set Enabled to false.

To hide a button, set Visible to false.

Run code when a user clicks the button.

Add code to the Click event handler.

Note

This interface is implemented by the Visual Studio Tools for Office runtime. It is not intended to be implemented in your code. For more information, see Visual Studio Tools for Office Runtime Overview.

Usage

This documentation describes the version of this type that is used in Office projects that target the .NET Framework 4 and the .NET Framework 4.5. In projects that target the .NET Framework 3.5, this type might have different members and the code examples provided for this type might not work. For documentation about this type in projects that target the .NET Framework 3.5, see the following reference section in the Visual Studio 2008 documentation: https://go.microsoft.com/fwlink/?LinkId=160658.

Examples

The following example creates a new button, sets various properties of the button, and then adds the button to a menu. To run this code example, you must first perform the following steps:

  1. Add a Ribbon (Visual Designer) item to a project created by using Office development tools in Visual Studio.

  2. Add a group to the custom tab.

  3. Add a menu to the group.

  4. Set the Dynamic property of the menu to true.

  5. Set the ItemSize property of the menu to RibbonControlSizeLarge.

Private Sub AddButtonsToMenu()
    Dim tempButton = Me.Factory.CreateRibbonButton()
    tempButton.Label = "Button 1"
    tempButton.ControlSize = _
        Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge
    tempButton.Description = "My Ribbon Button"
    tempButton.ShowImage = True
    tempButton.ShowImage = True
    tempButton.Image = My.Resources.Image1
    tempButton.Image = My.Resources.Image2
    tempButton.KeyTip = "A1"
    menu1.Items.Add(tempButton)
End Sub
private void AddButtonsToMenu()
{
    RibbonButton tempButton = this.Factory.CreateRibbonButton();
    tempButton.Label = "Button 1";
    tempButton.ControlSize =
        Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;
    tempButton.Description = "My Ribbon Button";
    tempButton.ShowImage = true;
    tempButton.ShowImage = true;
    tempButton.Image = Properties.Resources.Image1;
    tempButton.Image = Properties.Resources.Image2;
    tempButton.KeyTip = "A1";
    menu1.Items.Add(tempButton);

}

See Also

Reference

Microsoft.Office.Tools.Ribbon Namespace

RibbonMenu

RibbonButton

Other Resources

Ribbon Overview

Ribbon Designer

Ribbon Object Model Overview

How to: Get Started Customizing the Ribbon