C# – How to add the images to button using the ribbon xml

cnetribbonvsto

How to add the custom images to the ribbon button in the tab and the context menu.

I tried the link Adding Image to ribbon button but no luck :-(. I am designing the addin for Excel. I added this in the header.

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"  onLoad="Ribbon_Load"   loadImage="Ribbon_LoadImage"> 
    <button id="btn2d" keytip="L" screentip="2D Visualization" supertip="2D Part Visualization" label="2D" size="large"/>
    <contextMenu idMso="ContextMenuCell">
    <button id="btn1" label="my label"/>
    </customUI>

the code snippet

public Bitmap Ribbon_LoadImage(IRibbonControl control)
    {
        switch (control.Id)
        {
            case "btn2": return new Bitmap(Properties.Resources.btn1);
            case "btn3": return new Bitmap(Properties.Resources.btn2);
            case "btn4": return new Bitmap(Properties.Resources.btn3);
            case "btn5": return new Bitmap(Properties.Resources.Filter);
            case "btnOpt6": return new Bitmap(Properties.Resources.Settings);
            case "btnInform7": return new Bitmap(Properties.Resources.Vis);
            case "btnHelpPage": return new Bitmap(Properties.Resources.Help);
        }
        return null;
    }

Please help me in this.
I am using .net 4.0 c# VSTO excel addin for Office 2010.

Best Answer

You have to use getImage property for each button and the callback should return bitmap.

In Ribbon.xml

<button id="btnLogo" getImage="imageSuper_GetImage" size="large" />

Ribbon.cs

public Bitmap imageSuper_GetImage(IRibbonControl control)
        {
            return Resources.super_logo;
        }