Picture 属性

       

返回一个 IPictureDisp 对象,表示 CommandBarButton 对象的图像。

expression.Picture

expression   必需。该表达式返回一个 CommandBarButton 对象。

说明

在更改按钮图像时,还希望使用 Mask 属性设置屏蔽图像。屏蔽图像决定按钮图像透明的部分。通常在设置了 CommandBarButton 对象的图片后设置屏蔽。

注释  Visual Basic 编辑器中“常用”工具栏上的“查看 Microsoft 应用程序”和“插入”按钮上的图像不能更改。

示例

本示例设置代码返回的第一个 CommandBarButton 的图像和屏蔽。要使本示例正常工作,请创建屏蔽图像和按钮图像,并以图像的路径替换范例中的路径。

Sub ChangeButtonImage()
    Dim picPicture As IPictureDisp
    Dim picMask As IPictureDisp

    Set picPicture = stdole.StdFunctions.LoadPicture( _
        "c:\images\picture.bmp")
    Set picMask = stdole.StdFunctions.LoadPicture( _
        "c:\images\mask.bmp")

    'Reference the first button on the first command bar
    'using a With...End With block.
    With Application.CommandBars.FindControl(msoControlButton)
        'Change the button image.
        .Picture = picButton

        'Use the second image to define the area of the
        'button that should be transparent.
        .Mask = picMask
    End With
End Sub

本示例获得代码返回的第一个 CommandBarButton 的图像和屏蔽,并输出到文件。要使本示例正常工作,请指定输出文件的路径。


Sub GetButtonImageAndMask()
    Dim picPicture As IPictureDisp
    Dim picMask As IPictureDisp

    With Application.CommandBars.FindControl(msoControlButton)
        'Get the button image and mask of the this CommandBarButton object.
        Set picPicture = .Picture
        Set picMask = .Mask
    End With

    'Save the button image and mask in a folder.
    stdole.SavePicture picPicture, "c:\temp\image.bmp"
    stdole.SavePicture picMask, "c:\temp\mask.bmp"
End Sub