1

i'm developing a Visual Studio 2010 extension, i already have a toolbar inside my window. on that toolbar i have a button that i want to give an icon - my own icon! I've read this article and it is great but... it explains how to replace the icons.

i want to add an additional icon.

how do i achieve that?

shemesh
  • 311
  • 3
  • 18
  • Depends on how you're making your extension. Do you have a .vsct file in your project that contains the definition of your buttons? –  Feb 01 '12 at 14:14
  • yes i do have that! i think I've found an answer but would like to hear yours so i can learn and see if i'm doing right. – shemesh Feb 01 '12 at 21:38

2 Answers2

6

First, add the bitmap and set its build action to Resource

enter image description here

Remember, shocking pink = transparent (damn you, old school!)

enter image description here

Then, in your vsct file, add the image to the bitmaps section

<Bitmaps>
    <Bitmap guid="AddSampleData.bmpGuid"
            href="..\Button Bitmaps\AddSampleData.bmp"
            usedList="AddSampleData.bmpId" />
    <Bitmap guid="ApplySampleData.bmpGuid"
            href="..\Button Bitmaps\ApplySampleData.bmp"
            usedList="ApplySampleData.bmpId" />
</Bitmaps>

and assign it a guid in the symbols node

<Symbols>
    <!-- snip -->
    <GuidSymbol name="AddSampleData.bmpGuid"
                value="{dcae7c84-8e91-4f8a-907b-95ccb0f52e6e}">
        <IDSymbol name="AddSampleData.bmpId"
                    value="1" />
    </GuidSymbol>
    <GuidSymbol name="ApplySampleData.bmpGuid"
                value="{9f555245-2430-4e6f-992b-b49ce87a31a2}">
        <IDSymbol name="ApplySampleData.bmpId"
                    value="1" />
    </GuidSymbol>
</Symbols>

and apply it to a button

<Buttons>
<!-- snip -->
    <Button guid="guidEditorExtensionCommandSet"
            id="setDesignTimeDataOnPage"
            priority="0x0100">
        <Icon guid="ApplySampleData.bmpGuid"
                id="ApplySampleData.bmpId" />
        <Strings>
                    <!-- snip -->
        </Strings>
    </Button>
</Buttons>

Of course, its always easier to use the available tools, including the excellent VSPackage Builder extension.

enter image description here

  • 1
    great, tnx, that exactly what i did! BUT... with a .png not .bmp - it makes life easier when it come to transparency. the only difference is that you don't need the usedList inside the Bitmap tag. – shemesh Feb 01 '12 at 22:12
6

A workaround for this is to create a PNG and rename the extension as *.bmp. VS will accept it as an icon image and it will also have transparency (from Visual Studio Extensibility > Toolbox Icons -- Is transparency supported?)

Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121