Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

VSPackages: How to change icon of buttons dynamically

$
0
0

Hello, 

I am developing a VSX package( this is VSCT in C# 4 and VS2010). I wants to add a button and change the button icon dynamically. I would like to know is there any way that I can change the icon of button dynamically?

Details:

1) First, I add a button in VSCT:

...

<Button guid="cmdSet" id="cmdID" priority="0x0101" type="Button"><Parent guid="cmdSet" id="commGroup"/><Icon guid="guidImages" id="cmdIcon" /><CommandFlag>DynamicVisibility</CommandFlag><CommandFlag>DefaultDisabled</CommandFlag><Strings><CommandName>My Button</CommandName><ButtonText>My Button</ButtonText><ToolTipText>My Button</ToolTipText></Strings></Button>

...


2) I add this button in .cs code

private initial()
{
   ...
    var cmdid = new CommandID(guid, cmdIDInt);
    var cmd = new OleMenuCommand(DoNothingMenuInvoke, cmdid);
    cmd.BeforeQueryStatus += new QueryButtonStatus;
    menuservice.AddCommand(cmd);
   ...
}

3. In QueryButtonStatus, I only can change the enable, checked, visible, property. I can find a way to change icon!

private void QueryButtonStatus(object sender, EventArgs e)
        {
            OleMenuCommand menuCommand = sender as OleMenuCommand;
            menuCommand.Checked = true;
            menuCommand.Enabled = true;
            menuCommand.Visible = true;

        }

4. BTW, as I know, there is a way to change the icon of button in VS toolbar. But this button is not in tool bar. Therefore, currently I have no idea and comes here for help.

Thank you all.







Viewing all articles
Browse latest Browse all 4410

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>