RibbonMenu 介面

定義

代表功能區索引標籤或 Microsoft Office 功能表上的功能表。

public interface class RibbonMenu : IDisposable, Microsoft::Office::Tools::Ribbon::RibbonControl, System::ComponentModel::IComponent
[System.Runtime.InteropServices.Guid("59dc7f42-aca2-484a-9622-1ee34a6cfd7d")]
public interface RibbonMenu : IDisposable, Microsoft.Office.Tools.Ribbon.RibbonControl, System.ComponentModel.IComponent
[<System.Runtime.InteropServices.Guid("59dc7f42-aca2-484a-9622-1ee34a6cfd7d")>]
type RibbonMenu = interface
    interface RibbonControl
    interface RibbonComponent
    interface IComponent
    interface IDisposable
Public Interface RibbonMenu
Implements IComponent, IDisposable, RibbonControl
屬性
實作

範例

下列範例示範如何在運行時間將子功能表新增並填入現有的功能表。

如需在運行時間更新控件的更豐富範例,並牽涉到使用 Language-Integrated 查詢 (LINQ) 從 AdventureWorks 範例資料庫取得數據,請參閱逐步解說 :在運行時間更新功能區上的控件

若要執行此程式碼範例,您必須先執行下列步驟:

  1. 功能區 (Visual Designer) 專案新增至 Office 專案。

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

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

  4. 將選單的 (Name) 屬性設定為 CustomerMenu

  5. 將功能表的 Label 屬性設定為 [客戶]。

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

    在功能區載入至 Office 應用程式之後,這可讓您在執行階段加入和移除功能表上的控制項。

private void PopulateCustomerMenu()
{
    // Add two sub-menus to EmployeeMenu and populate each sub-menu
    // First sub-menu
    RibbonMenu subMenu1 = this.Factory.CreateRibbonMenu();
    subMenu1.Dynamic = true;
    subMenu1.Label = "A - M";
    subMenu1.Items.Add(this.Factory.CreateRibbonToggleButton());
    ((RibbonToggleButton)subMenu1.Items.Last()).Label = "Hall, Don";
    subMenu1.Items.Add(this.Factory.CreateRibbonToggleButton());
    ((RibbonToggleButton)subMenu1.Items.Last()).Label = "Valdez, Rachel";
    CustomerMenu.Items.Add(subMenu1);

    // Second sub-menu
    RibbonMenu subMenu2 = this.Factory.CreateRibbonMenu();
    subMenu2.Dynamic = true;
    subMenu2.Label = "N - Z";
    subMenu2.Items.Add(this.Factory.CreateRibbonToggleButton());
    ((RibbonToggleButton)subMenu2.Items.Last()).Label = "Robinson, Alex";
    CustomerMenu.Items.Add(subMenu2);
}
Private Sub PopulateCustomerMenu()
    ' Add two sub-menus to EmployeeMenu and populate each sub-menu
    ' First sub-menu
    Dim subMenu1 As RibbonMenu = Me.Factory.CreateRibbonMenu()
    subMenu1.Dynamic = True
    subMenu1.Label = "A - M"
    subMenu1.Items.Add(Me.Factory.CreateRibbonToggleButton())
    CType(subMenu1.Items.Last(), RibbonToggleButton).Label = "Hall, Don"
    subMenu1.Items.Add(Me.Factory.CreateRibbonToggleButton())
    CType(subMenu1.Items.Last(), RibbonToggleButton).Label = "Valdez, Rachel"
    CustomerMenu.Items.Add(subMenu1)

    ' Second sub-menu
    Dim subMenu2 As RibbonMenu = Me.Factory.CreateRibbonMenu()
    subMenu2.Dynamic = True
    subMenu2.Label = "N - Z"
    subMenu2.Items.Add(Me.Factory.CreateRibbonToggleButton())
    CType(subMenu2.Items.Last(), RibbonToggleButton).Label = "Robinson, Alex"
    CustomerMenu.Items.Add(subMenu2)

End Sub

備註

當您將功能表控件從 [工具箱] 的 [Office 功能區控件] 索引卷標拖曳到功能區 Designer 時,Visual Studio 會建立 RibbonMenu 物件。

您可以使用物件的 方法RibbonFactory,在執行時間CreateRibbonMenu建立 RibbonMenu

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

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

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

一般工作

下表列出適用於一般工作的成員。 所有這些工作都可以在設計時間執行。 其中一些工作只能在運行時間於功能區載入 Office 應用程式之前,或在運行時間將控件新增至動態功能表之前執行。 如需詳細資訊,請參閱 功能區物件模型概觀

工作 成員
在功能表上顯示影像。 Image使用或 ImageName 屬性。

您也可以重複使用出現在內建功能區控件中的影像。 若要這樣做,請將 設定 OfficeImageId 為您想要顯示為功能表圖示的內建 Microsoft Office 影像標識符。
變更功能表的大小。 ControlSize 屬性設定為您想要的值。 例如,如果是大型功能表,請將它設定為 Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge
變更功能表中的專案大小。 ItemSize 屬性設定為您想要的值。 例如,若要顯示較大的專案,請將它設定為 Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge
例如,在運行時間啟用功能表的變更 (,讓控件能夠在運行時間新增至功能表) 。 Dynamic 屬性設為 true
存取功能表中的控制項、將控制項新增至功能表,或從功能表中移除控制件。 請使用 Items 屬性。
將功能表新增至 Microsoft Office 功能表、群組或可包含功能表的另一個控制件。 RibbonMenu將 加入至 Items Microsoft Office 功能表、群組或控件的屬性。

注意

這個介面是由 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

取得或設定顯示在目前功能表上的文字。

Dynamic

取得或設定值,指出功能表是否可在執行階段修改。

Enabled

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

(繼承來源 RibbonControl)
Id

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

(繼承來源 RibbonControl)
Image

取得或設定顯示在功能表上的影像。

ImageName

取得或設定您在 LoadImage 事件處理常式中,用來識別功能表影像的名稱。

Items

取得功能表上的控制項集合。

ItemSize

取得或設定功能表上的控制項大小。

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

取得或設定當使用者展開新增至 Microsoft Office 功能表的功能表時所顯示的標題。

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)

事件

ItemsLoading

發生於控制項或巢狀功能表在執行階段載入到目前的功能表時。

適用於