Using built-in icons in Visual Studio extension

1.1k views Asked by At

What step do I need to follow to use some of the built-in icons of Visual Studio in my extension toolbar (e.g. Open, Save, Run, Break icons)?

I have tried using constants such as cmdidSave from stdidcmd.h in my VSCT file like this:

<Button guid="guidBBTWindowPackageCmdSet" id="cmdidMyButton1" priority="0x0101" type="Button">
    <Parent guid="guidBBTWindowPackageCmdSet" id="ToolbarGroupID"/>
    <Icon guid="CMDSETID_StandardCommandSet14" id="cmdidSave" />
    <Strings>
      <CommandName>cmdidMyCommand1</CommandName>
      <ButtonText>Load File</ButtonText>
    </Strings>
</Button>

But it doesn't show the icon. Instead it starts showing the button in text style (text caption instead of image).

On the other hand, it works fine if I use the "image strip method" (as done in the default extension template), but that's not what I want to do.

1

There are 1 answers

0
dotNET On BEST ANSWER

OK. So here it is in case anyone is struggling:

At the top of your VSCT file, include this reference:

<Include href="KnownImageIds.vsct"/>

Visual Studio (as of VS2015 Community Update 3) knows where this file is.

Now use ImageCatalogGuid as <Icon> node's GUID. Visual Studio Intellisense will list down all available icon for you to choose (you didn't expect it, right!).

<Button guid="guidCommand1PackageCmdSet" id="Command1Id" priority="0x0100" type="Button">
  <Parent guid="guidCommand1PackageCmdSet" id="MyMenuGroup" />
  <Icon guid="ImageCatalogGuid" id="CacheRefresh" />
  <CommandFlag>IconIsMoniker</CommandFlag>
  <Strings>
    <ButtonText>Invoke Command1</ButtonText>
  </Strings>
</Button>

Note the extra line <CommandFlag>IconIsMoniker</CommandFlag>. This must be included immediately after the <Icon> line.