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

RibbonButton.Image 屬性

 

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

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

Image Image { get; set; }

屬性值

Type: System.Drawing.Image

顯示在按鈕上的 Image

The recommended image format is PNG, because images in the PNG format support transparency through their alpha channel.

The P:Microsoft.Office.Tools.Ribbon.RibbonButton.Image property identifies an image that is displayed by the control. This property can be set at design time or at run time. If you update this property at run time, the control's appearance is updated to reflect the change.

If the P:Microsoft.Office.Tools.Ribbon.RibbonButton.Image property is set, the P:Microsoft.Office.Tools.Ribbon.RibbonButton.OfficeImageId and P:Microsoft.Office.Tools.Ribbon.RibbonButton.ImageName properties are ignored. Although the P:Microsoft.Office.Tools.Ribbon.RibbonButton.Image property gives you more control than the other two properties do, it can be slower because the image object is sent to the Office application every time the control is updated.

The P:Microsoft.Office.Tools.Ribbon.RibbonButton.ShowImage property must be true for the control to display the image. When you set the P:Microsoft.Office.Tools.Ribbon.RibbonButton.Image property at design time, Visual Studio automatically sets the P:Microsoft.Office.Tools.Ribbon.RibbonButton.ShowImage property to true. If you set the P:Microsoft.Office.Tools.Ribbon.RibbonButton.Image property at run time, you must set the P:Microsoft.Office.Tools.Ribbon.RibbonButton.ShowImage property to true in your code.

The following example sets the P:Microsoft.Office.Tools.Ribbon.RibbonButton.Image property of two buttons. 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 two buttons to the group.

  4. Add two images to the project resources.

private void LoadImages()
{
    button1.ShowImage = true;
    button2.ShowImage = true;
    button1.Image = Properties.Resources.Image1;
    button2.Image = Properties.Resources.Image2;
}
回到頁首
顯示: