RibbonButton 介面

定義

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

public interface class RibbonButton : IDisposable, Microsoft::Office::Tools::Ribbon::RibbonControl, System::ComponentModel::IComponent
[System.Runtime.InteropServices.Guid("b57e6217-33f2-46bf-9625-c313526de60c")]
public interface RibbonButton : IDisposable, Microsoft.Office.Tools.Ribbon.RibbonControl, System.ComponentModel.IComponent
[<System.Runtime.InteropServices.Guid("b57e6217-33f2-46bf-9625-c313526de60c")>]
type RibbonButton = interface
    interface RibbonControl
    interface RibbonComponent
    interface IComponent
    interface IDisposable
Public Interface RibbonButton
Implements IComponent, IDisposable, RibbonControl
屬性
實作

範例

下列範例會建立新的按鈕、設定按鈕的各種屬性,然後將按鈕新增至功能表。 若要執行此程式碼範例,您必須先執行下列步驟:

  1. 功能區 (Visual Designer) 專案新增至使用 Visual Studio 中的 Office 開發工具所建立的專案。

  2. 將群組新增至自定義索引標籤。

  3. 將功能表新增至群組。

  4. 將選單的 Dynamic 屬性設定為 true

  5. 將功能表的 ItemSize 屬性設定為 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);

}
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

備註

當您從 [工具箱] 的 [Office 功能區控件] 索引標籤將 [按鈕] 控件拖曳至功能區 Designer 時,Visual Studio 會建立類別的實例,以實RibbonButton作介面。

您也可以在運行時間建立此控件的實例,並將它新增至動態功能表。 如果您將其 Dynamic 屬性設定為 true,則功能表是動態的。

此控制項的某些屬性只能在功能區載入 Office 應用程式之前設定,或在運行時間將控制項新增至動態功能表之前設定。 如需設定這些屬性的詳細資訊,請參閱 功能區物件模型概觀

您可以使用物件的 方法RibbonFactoryCreateRibbonButton在執行時間建立 RibbonButton

有兩種方法可以存取 RibbonFactory 物件:

  • 使用功能區類別的 Factory 屬性。 請從功能區類別中的程式碼使用此方法。

  • 使用 Globals.Factory.GetRibbonFactory 方法。 請從功能區類別外的程式碼使用此方法。

一般工作

下表列出適用於一般工作的成員。

工作 成員
在運行時間,將按鈕新增至功能表,其 Dynamic 屬性設定為 true。 使用 來建立實作 介面之 RibbonButton 類別的實例 CreateRibbonButton

類別的 RibbonFactory 方法。 如需詳細資訊,請參閱 Office 專案中物件的全域存取

將實例新增至功能表的 Items 集合。
變更按鈕的大小。 設定 ControlSize 為您想要的值。 例如,如果是大型按鈕,請將它設定為 Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge
在按鈕上顯示影像。 有三種方式可以顯示影像:

- 使用 Image 屬性。 這個屬性會提供最多控制件。
- 設定 OfficeImageId 為您想要顯示為按鈕圖示的內建 Microsoft Office 映射識別碼。
- 使用 ImageName 屬性以及 LoadImage 事件。 此屬性提供一些效能優點。
停用或隱藏按鈕。 若要停用按鈕,請將 設定 Enabledfalse

若要隱藏按鈕,請將 設定 Visiblefalse
當使用者按鍵時執行程序代碼。 將程式代碼新增至 Click 事件處理程式。

注意

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

使用方式

本文件說明此類型的版本,其會用在目標為 .NET Framework 4 或更新版本的 Office 專案中。 在以 .NET Framework 3.5 為目標的專案中,此類型可能會有不同的成員,而為此類型提供的程式碼範例可能無法運作。 如需此類型在以 .NET Framework 3.5 為目標專案中的相關文件,請參閱下列 Visual Studio 2008 文件中的參考章節:http://go.microsoft.com/fwlink/?LinkId=160658

屬性

ControlSize

取得或設定按鈕的大小。

Description

取得或設定當功能表的 屬性設定為 Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge 時 ItemSize ,此按鈕上出現的文字。

Enabled

取得或設定值,指出是否啟用這個 RibbonControl

(繼承來源 RibbonControl)
Id

取得字串,Microsoft Office 用來識別這個 RibbonControl 物件。

(繼承來源 RibbonControl)
Image

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

ImageName

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

KeyTip

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

Label

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

Name

取得或設定這個 RibbonComponent 的名稱。

(繼承來源 RibbonComponent)
OfficeImageId

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

Parent

取得 RibbonComponent,代表這個 RibbonComponent 的父代。

(繼承來源 RibbonComponent)
Position

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

Ribbon

取得包含控制項階層的最上層 Ribbon 物件。

(繼承來源 RibbonComponent)
RibbonUI

取得 Microsoft Office 應用程式提供給功能區擴充性程式碼的 IRibbonUI 執行個體。

(繼承來源 RibbonComponent)
ScreenTip

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

ShowImage

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

ShowLabel

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

SuperTip

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

Tag

取得或設定與這個 RibbonComponent 關聯的應用程式特定資料。

(繼承來源 RibbonComponent)
Visible

取得或設定值,指出這個 RibbonControl 是否可見。

(繼承來源 RibbonControl)

方法

PerformDynamicLayout()

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

(繼承來源 RibbonComponent)
PerformLayout()

如果 具有父代,而且未暫止配置,請呼叫 RibbonComponentMicrosoft.Office.Core.IRibbonUI.InvalidateControl。

(繼承來源 RibbonComponent)
ResumeLayout()

回復 SuspendLayout() 方法的效果。

(繼承來源 RibbonComponent)
ResumeLayout(Boolean)

回復 SuspendLayout() 方法的效果。

(繼承來源 RibbonComponent)
SuspendLayout()

防止 Microsoft Office 應用程式重新整理功能區上控制項的狀態。

(繼承來源 RibbonComponent)

事件

Click

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

適用於