共用方式為


RibbonButton.ImageName 屬性 (2007 系統)

更新:2007 年 11 月

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

命名空間:  Microsoft.Office.Tools.Ribbon
組件:  Microsoft.Office.Tools.Common.v9.0 (在 Microsoft.Office.Tools.Common.v9.0.dll 中)

語法

Public Property ImageName As String

Dim instance As RibbonButton
Dim value As String

value = instance.ImageName

instance.ImageName = value
public string ImageName { get; set; }

屬性值

型別:System.String

字串,您可以在 LoadImage 事件處理常式中用來識別按鈕。

備註

這個屬性只能在特定條件下於執行階段設定。如需詳細資訊,請參閱功能區物件模型概觀

如需設定這個屬性的資訊,請參閱功能區物件模型概觀

ImageName 屬性可以識別控制項顯示的影像。Office 應用程式只會從方案擷取這個影像一次,以提高效能。這個屬性可以在設計階段時設定,因為它所定義的影像會在 LoadImage 事件期間載入。當功能區顯示時,每一個影像名稱只會引發一次 LoadImage。之後就不能使用這個屬性變更控制項影像。

若要載入影像,請將程式碼加入至 LoadImage 事件處理常式。查看 RibbonLoadImageEventArgsImageName 屬性,並將 RibbonLoadImageEventArgs 物件的 Image 屬性設定為您要載入的影像。

如果 Image 屬性或 OfficeImageId 屬性已設定,則會忽略這個屬性。因為 Office 應用程式只會在第一次顯示功能區時從方案中擷取影像,所以載入 ImageName 屬性識別的影像時,可能會比載入 Image 屬性識別的影像稍微快一些。

ShowImage 屬性必須為 true,控制項才能顯示影像。當您在設計階段設定 ImageName 屬性時,Visual Studio Tools for Office 會自動將 ShowImage 屬性設定為 true。如果是在執行階段設定 ImageName 屬性,您必須在程式碼中,將 ShowImage 屬性設定為 true。

範例

下列範例會快取兩個按鈕的影像。

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

  1. 將 [功能區 (視覺化設計工具)] 項目加入至 Visual Studio Tools for Office 專案。

  2. 將群組加入至自訂索引標籤。

  3. 將兩個按鈕加入至群組。

  4. 將兩個影像加入至專案資源。如需詳細資訊,請參閱 HOW TO:加入或移除資源

然後您可以在產生的功能區類別中執行這個程式碼。

Private Sub Ribbon1_LoadImage(ByVal sender As Object, _
    ByVal e As RibbonLoadImageEventArgs)
    Select Case e.ImageName
        Case "Button1Image"
            e.Image = My.Resources.Image1
        Case "Button2Image"
            e.Image = My.Resources.Image2
    End Select
End Sub
private void Ribbon1_LoadImage(object sender, RibbonLoadImageEventArgs e)
{
    switch (e.ImageName)
    {
        case "Button1Image":
            e.Image = Properties.Resources.Image1;
            break;
        case "Button2Image":
            e.Image = Properties.Resources.Image2;
            break;
    }
}

使用權限

請參閱

參考

RibbonButton 類別

RibbonButton 成員

Microsoft.Office.Tools.Ribbon 命名空間

其他資源

功能區概觀

功能區物件模型概觀