Mark Lalor Mark Lalor - 1 year ago 104
C# Question

Visual Studio Images with Ribbons (XML)

I'm making Office 2007 addins and I'm trying to use XML instead of the visual designer to customize the ribbon but for some reason I cant get an image to work with it... What exactly do you have to do‽ I added a resource png called Icon1 and tried this:

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="" onLoad="Ribbon_Load">
<ribbon startFromScratch="false">
<tab id="TabToolss" label="Tools">
<group id="MyGroup" label="My Group" visible="true">

No luck... not sure why. Even if I put the full file path in there it doesn't work.

I've never gotten it to work once, so maybe I'm just not doing it the way it was made to be done...

Answer Source

Very complicated solution... lucky to find it here

First add loadImage attribute to CustomUI tab,

Then to simplify things, add this internal class

internal class PictureConverter : AxHost
        private PictureConverter() : base(String.Empty) { }

        static public stdole.IPictureDisp ImageToPictureDisp(Image image)
            return (stdole.IPictureDisp)GetIPictureDispFromPicture(image);

        static public stdole.IPictureDisp IconToPictureDisp(Icon icon)
            return ImageToPictureDisp(icon.ToBitmap());

        static public Image PictureDispToImage(stdole.IPictureDisp picture)
            return GetPictureFromIPicture(picture);

Next add definition of loadImage function,

public IPictureDisp Ribbon_LoadImage(string imageName)
            return PictureConverter.ImageToPictureDisp((Bitmap)Resources.ResourceManager.GetObject(imageName));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download