设置 CommandBar“弹出”动态子菜单图标
我只是想确认这一点:在 Office 2003 中,我想在运行时创建一个自定义子菜单(在 CommandBar 中称为弹出窗口 (msoControlPopup)),并为其设置一个图像。对于 CommandBarButton,这非常简单,
Set btn1 = mnu.Controls.Add(msoControlButton, temporary:=True)
btn1.Caption = "Btn1"
btn1.Picture = stdole.LoadPicture("C:\temp\test.bmp")
但对于 CommandBarPopup 或 msoControlPopup 类型的 CommandBarControl,它会失败
Set sub1 = mnu.Controls.Add(msoControlPopup, temporary:=True)
sub1.Caption = "Sub1"
'object doesn't support this property or method for next line
sub1.Picture = stdole.LoadPicture("C:\temp\test.bmp")
msoControlPopup 类型似乎也不允许 .Style
属性,这就是 Office 确定要显示的内容的方式在控件上显示-图标、文本、两者。我还没有发现这一点得到证实,所以我抱着最后的希望,认为我做错了什么,事实上,有一种方法可以在运行时在子菜单上插入图标。
感谢您能提供的任何光芒。
I'm just trying to confirm this: In Office 2003, I want to create a custom submenu--what is known in CommandBar parlance as a popup (msoControlPopup)--at runtime, and set an image for it. With a CommandBarButton, this is very straightforward
Set btn1 = mnu.Controls.Add(msoControlButton, temporary:=True)
btn1.Caption = "Btn1"
btn1.Picture = stdole.LoadPicture("C:\temp\test.bmp")
But with a CommandBarPopup, or CommandBarControl of type msoControlPopup, it fails
Set sub1 = mnu.Controls.Add(msoControlPopup, temporary:=True)
sub1.Caption = "Sub1"
'object doesn't support this property or method for next line
sub1.Picture = stdole.LoadPicture("C:\temp\test.bmp")
The msoControlPopup type doesn't seem to allow a .Style
property either, which is how Office determines what to show--icon, text, both--on the control. I haven't found this proven yet, so am holding out a last hope that I'm doing something wrong, and there is, in fact, a way to insert an icon on a submenu at runtime.
Thanks for any light you can shed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,还有更多的风滚草。我很确定这个问题的答案是,这是不可能的。这是我的“证据”:所有内置子菜单都没有图标(直到我发布上述内容之后我才意识到这一点,如果您运行上面的代码,请转到“工具”>“在菜单栏中自定义,然后单击“测试”菜单将其下拉,然后右键单击“Sub1”,您应该看到所有按钮和样式选项都变灰。右键单击“Btn1”,它们是可用的
。想法仍然受欢迎。
Ok well more tumbleweeds. I'm pretty sure the answer to this is, it can't be done. And here's my "proof": None of the built-in submenus have icons (which I didn't realize until after I posted the above, and if you run the above code, go to Tools > Customize in the menu bar, then click on the Test menu to drop it down, and right-click on Sub1, you should see all the button and style options greyed out. Right-click on Btn1, and they're available.
Any other thoughts still welcome.
当然,如果您需要设置子菜单标题的图像或 FaceID,这不是子菜单标题的可用方法,但如果您想在子菜单本身上设置图像或 FaceID,我修改了 此处 来完成此操作:
我对此进行了测试,它似乎工作正常对于 FaceID 和加载的图片。
当然,为了获得“运行时”效果,我建议将其放置在一个函数中,每次用户单击特定控件时都会调用该函数。
它也可以进一步扩展以处理此处的可变图片。
希望这有帮助。
Of course if you need to set the image or FaceID of the submenu heading, that is not an available method for submenu headings, but if you want to set the image or FaceID on the submenu itself, I modified code from here to accomplish this:
I tested this and it appears to work fine for both FaceID's and loaded pictures.
Of course to get the "on run time" affect, I would recommend placing this in a function which was called each time the user clicked on a specific control.
It could be further expended to handle variable pictures here as well.
Hope this helps.