Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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)
[GuidAttribute("b57e6217-33f2-46bf-9625-c313526de60c")]
public interface RibbonButton : RibbonControl, 
	RibbonComponent, IComponent, IDisposable

The RibbonButton type exposes the following members.

  NameDescription
Public propertyControlSizeGets or sets the size of the button.
Public propertyDescriptionGets 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 propertyEnabledGets or sets a value that indicates whether this RibbonControl is enabled. (Inherited from RibbonControl.)
Public propertyIdGets a string that Microsoft Office uses to identify this RibbonControl object. (Inherited from RibbonControl.)
Public propertyImageGets or sets the image that is displayed on the button.
Public propertyImageNameGets or sets the name that you can use to identify the button in the LoadImage event handler.
Public propertyKeyTipGets or sets the keyboard shortcut of the button.
Public propertyLabelGets or sets the text that is displayed on the button.
Public propertyNameGets or sets the name of this RibbonComponent. (Inherited from RibbonComponent.)
Public propertyOfficeImageIdGets or sets the image to display on the button, if you want to use a built-in Microsoft Office icon.
Public propertyParentGets a RibbonComponent that represents the parent of this RibbonComponent. (Inherited from RibbonComponent.)
Public propertyPositionGets or sets the position of the button, if the button is on the Microsoft Office Menu.
Public propertyRibbonGets the top-level Ribbon object that contains the control hierarchy. (Inherited from RibbonComponent.)
Public propertyRibbonUIInfrastructure. Gets the IRibbonUI instance that is provided by the Microsoft Office application to the Ribbon extensibility code. (Inherited from RibbonComponent.)
Public propertyScreenTipGets or sets tooltip text that appears when the user moves the pointer over the button.
Public propertyShowImageGets or sets a value that indicates whether the image that is associated with the button is visible.
Public propertyShowLabelGets or sets a value that indicates whether the label for the button is visible.
Public propertySiteGets or sets the ISite associated with the IComponent. (Inherited from IComponent.)
Public propertySuperTipGets or sets multiline tip text that appears when the user moves the pointer over the button.
Public propertyTagGets or sets application-specific data that is associated with this RibbonComponent. (Inherited from RibbonComponent.)
Public propertyVisibleGets or sets a value that indicates whether this RibbonControl is visible. (Inherited from RibbonControl.)
Top
  NameDescription
Public methodDisposePerforms application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.)
Public methodPerformDynamicLayoutCalls 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 methodPerformLayoutCalls Microsoft.Office.Core.IRibbonUI.InvalidateControl if the RibbonComponent has a parent and layout is not suspended. (Inherited from RibbonComponent.)
Public methodResumeLayout()Reverses the effect of the SuspendLayout method. (Inherited from RibbonComponent.)
Public methodResumeLayout(Boolean)Reverses the effect of the SuspendLayout method. (Inherited from RibbonComponent.)
Public methodSuspendLayoutPrevents the Microsoft Office application from refreshing the state of controls on the Ribbon. (Inherited from RibbonComponent.)
Top
  NameDescription
Public eventClickOccurs when the user clicks the button.
Public eventDisposedRepresents the method that handles the Disposed event of a component. (Inherited from IComponent.)
Top

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.

NoteNote

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. 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: http://go.microsoft.com/fwlink/?LinkId=160658.

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 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);

}


Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.