目录

Mask 属性

优质
小牛编辑
118浏览
2023-12-01

返回表示 CommandBarButton 对象的屏蔽图像的IPictureDisp 对象。屏蔽图像决定按钮图像透明的部分。

expression.Mask

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

说明

在创建要作为屏蔽图像使用的图像时,所有要透明的区域应该为白色,所有要显示的区域应该为黑色。

通常在设置了 CommandBarButton 对象的图片后设置屏蔽。

示例

本示例设置代码返回的第一个 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