本文為機器翻譯文章。如需檢視英文版,請選取 [原文] 核取方塊。您也可以將滑鼠指標移到文字上,即可在快顯視窗顯示英文原文。
譯文
原文

RibbonButton 介面

 

表示自訂功能區上的按鈕。

命名空間:   Microsoft.Office.Tools.Ribbon
組件:  Microsoft.Office.Tools.Common (於 Microsoft.Office.Tools.Common.dll)

[GuidAttribute("b57e6217-33f2-46bf-9625-c313526de60c")]
public interface RibbonButton : RibbonControl, RibbonComponent, 
	IComponent, IDisposable

名稱描述
System_CAPS_pubpropertyControlSize

取得或設定按鈕的大小。

System_CAPS_pubpropertyDescription

取得或設定在這個功能表中的按鈕上顯示的文字時ItemSize] 功能表上的屬性設定為Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge

System_CAPS_pubpropertyEnabled

取得或設定值,指出是否啟用這個 RibbonControl(繼承自 RibbonControl。)

System_CAPS_pubpropertyId

取得字串,Microsoft Office 用來識別這個 RibbonControl 物件。(繼承自 RibbonControl。)

System_CAPS_pubpropertyImage

取得或設定顯示在按鈕上的影像。

System_CAPS_pubpropertyImageName

取得或設定可在 LoadImage 事件處理常式中用來識別按鈕的名稱。

System_CAPS_pubpropertyKeyTip

取得或設定按鈕的鍵盤快速鍵。

System_CAPS_pubpropertyLabel

取得或設定顯示在按鈕上的文字。

System_CAPS_pubpropertyName

取得或設定這個名稱RibbonComponent(繼承自 RibbonComponent。)

System_CAPS_pubpropertyOfficeImageId

取得或設定要顯示在按鈕上的影像 (如果想要使用內建的 Microsoft Office 圖示)。

System_CAPS_pubpropertyParent

取得 RibbonComponent,代表這個 RibbonComponent 的父代。(繼承自 RibbonComponent。)

System_CAPS_pubpropertyPosition

取得或設定按鈕的位置 (如果 Microsoft Office 功能表上有此按鈕)。

System_CAPS_pubpropertyRibbon

取得包含控制項階層的最上層 Ribbon 物件。(繼承自 RibbonComponent。)

System_CAPS_pubpropertyRibbonUI

此 API 支援 產品 基礎結構,而且不適合直接從程式碼使用。 取得 Microsoft Office 應用程式提供給功能區擴充性程式碼的 IRibbonUI 執行個體。(繼承自 RibbonComponent。)

System_CAPS_pubpropertyScreenTip

取得或設定當使用者將游標移至按鈕上方時所顯示的工具提示文字。

System_CAPS_pubpropertyShowImage

取得或設定值,指出與按鈕關聯的影像是否可見。

System_CAPS_pubpropertyShowLabel

取得或設定值,指出按鈕的標籤是否可見。

System_CAPS_pubpropertySite

(繼承自 IComponent。)

System_CAPS_pubpropertySuperTip

取得或設定當使用者將游標移至按鈕上方時所顯示的多行提示文字。

System_CAPS_pubpropertyTag

取得或設定與這個 RibbonComponent 相關聯的應用程式特定資料。(繼承自 RibbonComponent。)

System_CAPS_pubpropertyVisible

取得或設定值,指出這個 RibbonControl 是否可見。(繼承自 RibbonControl。)

名稱描述
System_CAPS_pubmethodDispose()

(繼承自 IDisposable。)

System_CAPS_pubmethodPerformDynamicLayout()

如果 RibbonComponent 具有動態功能表這類的動態父代,而且未暫停配置,請呼叫父控制項的 Microsoft.Office.Core.IRibbonUI.InvalidateControl 方法。(繼承自 RibbonComponent。)

System_CAPS_pubmethodPerformLayout()

如果 RibbonComponent 具有父系而未暫停配置即呼叫 Microsoft.Office.Core.IRibbonUI.InvalidateControl(繼承自 RibbonComponent。)

System_CAPS_pubmethodResumeLayout()

回復 SuspendLayout 方法的效果。(繼承自 RibbonComponent。)

System_CAPS_pubmethodResumeLayout(Boolean)

回復 SuspendLayout 方法的效果。(繼承自 RibbonComponent。)

System_CAPS_pubmethodSuspendLayout()

防止 Microsoft Office 應用程式重新整理功能區上控制項的狀態。(繼承自 RibbonComponent。)

名稱描述
System_CAPS_pubeventClick

發生於使用者按一下按鈕時。

System_CAPS_pubeventDisposed

(繼承自 IComponent。)

Visual Studio creates an instance of a class that implements the T:Microsoft.Office.Tools.Ribbon.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 P:Microsoft.Office.Tools.Ribbon.RibbonMenu.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 T:Microsoft.Office.Tools.Ribbon.RibbonButton at run time by using the M:Microsoft.Office.Tools.Ribbon.RibbonFactory.CreateRibbonButton method of the T:Microsoft.Office.Tools.Ribbon.RibbonFactory object.

There are two ways to access the T:Microsoft.Office.Tools.Ribbon.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.

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 P:Microsoft.Office.Tools.Ribbon.RibbonMenu.Dynamic property set to true.

Create an instance of a class that implements the T:Microsoft.Office.Tools.Ribbon.RibbonButton interface by using the M:Microsoft.Office.Tools.Ribbon.RibbonFactory.CreateRibbonButton

method of the T:Microsoft.Office.Tools.Ribbon.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 P:Microsoft.Office.Tools.Ribbon.RibbonButton.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 P:Microsoft.Office.Tools.Ribbon.RibbonButton.Image property. This property gives the most control.

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

  • Use the P:Microsoft.Office.Tools.Ribbon.RibbonButton.ImageName property along with the E:Microsoft.Office.Tools.Ribbon.OfficeRibbon.LoadImage event. This property gives some performance benefits.

Disable or hide buttons.

To disable a button, set P:Microsoft.Office.Tools.Ribbon.RibbonControl.Enabled to false.

To hide a button, set P:Microsoft.Office.Tools.Ribbon.RibbonControl.Visible to false.

Run code when a user clicks the button.

Add code to the E:Microsoft.Office.Tools.Ribbon.RibbonButton.Click event handler.

System_CAPS_note注意

這個介面是由 Visual Studio Tools for Office Runtime 實作, 並不能實作於您的程式碼中。 如需詳細資訊,請參閱Visual Studio Tools for Office Runtime 概觀

本文件說明此類型的版本,其會用在目標為 .NET Framework 4 或更新版本的 Office 專案中。 在以 .NET Framework 3.5 為目標的專案中,此類型可能會有不同的成員,而為此類型提供的程式碼範例可能無法運作。 如需此類型在以 .NET Framework 3.5 為目標之專案中的相關文件,請參閱下列 Visual Studio 2008 文件中的參考章節: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);

}
回到頁首
顯示: