当前位置:文档之家› 自定义工具栏按钮图标

自定义工具栏按钮图标

sp 对 象 , 语法如 下exp:ressio
n.Mask
参数是必 需的,返 回一个 Command BarButton 对象。
屏蔽图像 决定按钮
图像透明 的部分。 在创建作
为屏蔽图 像使用的
图像时, 所有要透
明的区域
应该为白
色,所有
要显示的 区域应该
为黑色。
第 11 行 代
码,设置
按钮的“ 屏幕提示
On Error Resume Next
Байду номын сангаас
Applicati man dBars("Cu stomBar") .Delete
Set
xBar
=
CommandBa
rs.Add("C
ustomBar"
,
msoBarTop
)
Set xButton = xBar.Cont rols.Add( msoContro lButton)
第 10 行 代 码,设置 工具栏按 钮 的 Mask 属性为同 一目录中 的 m.bmp 图片。 为了使工 具栏按钮 图标透明 显示,在 指定对象 的 Picture 属性后, 还需要指 定对象的 Mask 属 性 。 应用于 Command BarButton 对象的 Mask 属 性 返回表示 Command BarButton 对象的屏 蔽图像的 IPictureDi
With xButton
.Picture
=
LoadPictu
re(ThisWo
rkbook.Pa
th
&
"\P.BMP")
.Mask
=
LoadPictu
re(ThisWo
rkbook.Pa
th
&
"\M.BMP")
.TooltipT
ext
=
"Excel
Home 论 坛
" End
With
xBar.Visi
”为“ ExcelHom
e论坛”。


AddCusto
mButton 过
程,创建 自定义工
具栏,并 设置工具
栏按钮的
图标,如 图 90 ?1 所
示。
图 90?1自定义工具栏图标
技巧 1
自定 义工具
栏按钮
图标
在创建自 定义的工 具栏时, 除了可以 为工具栏 按钮添加 Excel 内 置 的图标 外,还能 为工具栏 按钮添加 自定义的 图标,如 下面的代 码所示。
Sub AddCustom Button()
Dim
xBar
As
CommandBa
r
Dim xButton As CommandBa rButton
ble
=
True
Set
xBar
=
Nothing
Set xButton = Nothing
End Sub
代码解 析: AddCusto
mButton 过 程创建自 定义工具 栏,并设 置工具栏 的按钮自 定义图标 。
第6、7行 代码,使 用 Add 方法 在 Excel 窗
口中添加 自定义工 具栏和按 钮。请参 阅 技 巧 89

第9行代
码,设置
工具栏按


Picture 属
性为同一 目录中的
p.bmp 图
片。
应用于
Command
BarButton
对象的
Picture 属
性返回一

IPictureDi
sp 对 象 ,


Command
BarButton
对象的图 像,语法
如下:
expressio
n.Picture
参数是必 需的,返 回一个 Command BarButton 对象。 指定对象 的 Picture 属性就能 设置对象 的图像。
相关主题