使用Visual Studio SDK更改按钮图标 [英] Changing a buttons icon in with the visual studio SDK

查看:245
本文介绍了使用Visual Studio SDK更改按钮图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio SDK向Visual Studio中添加一些其他功能.

I am using the Visual Studio SDK to add in some additional functionality to visual studio.

我有一个按钮,当按下该按钮时,它将执行可能会长时间运行的任务(可能需要10到15秒),并且我想更改按钮图标"以包含一些指示该任务正在执行的指示,然后再次更改该图标表示任务已完成.

I have a button that when pressed will perform a potentially long running task (maybe 10-15 seconds) and I would like to change the button Icon to include some indication that the task is being performed, and then again change the icon to show that the task has been completed.

通读MSDN文章向我展示了如何自定义图标,但是我在弄清楚如何在运行时更改图标时遇到了麻烦. MSDN文章在xml配置文件中配置其图标.

Reading through the MSDN articles has shown me how to customise my icon, but I am having trouble figuring out how to change it at run time. The MSDN article configures its icons in an xml config file.

基本上,我的问题是如何控制代码中的按钮图标?我在下面提供了我一直在使用的MSDN文章的链接

Essentially my question is how do I control the button icon in code? I have provided the link to the MSDN article that I have been using below

http://msdn.microsoft.com/en-us/library/bb165158.aspx

预先感谢

詹姆斯

推荐答案

这不是一个好主意(这是非标准的,您可以使用进度对话框或VS的状态栏),但是如果您确实愿意,可以尝试以下方法:

It is not a good idea (it's non standard, you can use a progress dialog or the status bar of VS instead), but if you really want you can try the following approach:

1)获取具有按钮的CommandBar

1) Get the CommandBar that has the button

2)在CommandBar.Controls集合中获取CommandBarControl

2) Get the CommandBarControl in the CommandBar.Controls collection

3)将CommandBarControl强制转换为CommandBarButton

3) Cast the CommandBarControl to CommandBarButton

4)使用CommandBarButton.Picture和CommandBarButton.Mask属性.请参阅我的文章的第2部分:

4) Use the CommandBarButton.Picture and CommandBarButton.Mask properties. See section #2 of my article:

如何:为Visual Studio .NET加载项命令,按钮和工具窗口创建自定义图片.

这篇关于使用Visual Studio SDK更改按钮图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆