CommandBarButton.Mask 属性 (Office)
获取或设置代表 CommandBarButton 对象的屏蔽图像的 IPictureDisp 对象。 屏蔽图像可决定按钮图像的透明部分。 读/写。
注意
某些 Microsoft Office 应用程序中对 CommandBars 的使用已由 Microsoft Office Fluent 用户界面的新功能区组件取代。 有关详细信息,请参阅 Office Fluent 功能区概述。
语法
表达式。面具
表达 一个代表 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 = picPicture
'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 this CommandBarButton object
Set picPicture = .Picture
Set picMask = .Mask
End With
'Save the button image and mask in a folder.
stdole.SavePicture picPicture, "c:\image.bmp"
stdole.SavePicture picMask, "c:\mask.bmp"
End Sub
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈