none
Showing the image next to the button in RIBBON XML RRS feed

  • Question

  • hey,

    i am puuting the image path in image attribute like 'd:\jjjljlklk.bmp' in button in RIBBON XML.

    the image is not shown even the image is there and path is correct.

    Thursday, December 15, 2011 6:24 AM

Answers

  • Hello,

    The Ribbon API works in a different way. You need to read Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3).


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader
    Thursday, December 15, 2011 6:29 AM
  • Hi ArchanaSinghvi,

     

    Thanks for posting in the MSDN Forum.

     

    I will show you a sample for your goal. I reproduce your issue under Visual Studio 2010, Office 2010, VSTO runtime 4.0.

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">
            <group id="MyGroup"
                   label="My Group">
              <button id="Test" label ="Test" getImage="GetImage" size="large"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    

     

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Text;
    using Office = Microsoft.Office.Core;
    using System.Drawing;
    
    // TODO:  Follow these steps to enable the Ribbon (XML) item:
    
    // 1: Copy the following code block into the ThisAddin, ThisWorkbook, or ThisDocument class.
    
    //  protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
    //  {
    //      return new Ribbon1();
    //  }
    
    // 2. Create callback methods in the "Ribbon Callbacks" region of this class to handle user
    //    actions, such as clicking a button. Note: if you have exported this Ribbon from the Ribbon designer,
    //    move your code from the event handlers to the callback methods and modify the code to work with the
    //    Ribbon extensibility (RibbonX) programming model.
    
    // 3. Assign attributes to the control tags in the Ribbon XML file to identify the appropriate callback methods in your code.  
    
    // For more information, see the Ribbon XML documentation in the Visual Studio Tools for Office Help.
    
    
    namespace ExcelAddIn13
    {
        [ComVisible(true)]
        public class Ribbon1 : Office.IRibbonExtensibility
        {
            private Office.IRibbonUI ribbon;
    
            public Ribbon1()
            {
            }
    
            #region IRibbonExtensibility Members
    
            public string GetCustomUI(string ribbonID)
            {
                return GetResourceText("ExcelAddIn13.Ribbon1.xml");
            }
    
            #endregion
    
            #region Ribbon Callbacks
            //Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1
    
            public void Ribbon_Load(Office.IRibbonUI ribbonUI)
            {
                this.ribbon = ribbonUI;
            }
    
            #endregion
    
            #region Helpers
    
            private static string GetResourceText(string resourceName)
            {
                Assembly asm = Assembly.GetExecutingAssembly();
                string[] resourceNames = asm.GetManifestResourceNames();
                for (int i = 0; i < resourceNames.Length; ++i)
                {
                    if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
                        {
                            if (resourceReader != null)
                            {
                                return resourceReader.ReadToEnd();
                            }
                        }
                    }
                }
                return null;
            }
    
            #endregion
    
            public Bitmap GetImage(Office.IRibbonControl Control)
            {
                Bitmap result = null;
                switch (Control.Id)
                {
                    case "Test":
                        result = new Bitmap(@"C:\*******\XZ.bmp");
                        break;
                }
                return result;
            }
        }
    }
    

     

     

     

    I hope it can help you.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, December 20, 2011 7:16 AM
    Moderator

All replies

  • Hello,

    The Ribbon API works in a different way. You need to read Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3).


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader
    Thursday, December 15, 2011 6:29 AM
  • Hi ArchanaSinghvi,

     

    Thanks for posting in the MSDN Forum.

     

    I will show you a sample for your goal. I reproduce your issue under Visual Studio 2010, Office 2010, VSTO runtime 4.0.

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">
            <group id="MyGroup"
                   label="My Group">
              <button id="Test" label ="Test" getImage="GetImage" size="large"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    

     

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Text;
    using Office = Microsoft.Office.Core;
    using System.Drawing;
    
    // TODO:  Follow these steps to enable the Ribbon (XML) item:
    
    // 1: Copy the following code block into the ThisAddin, ThisWorkbook, or ThisDocument class.
    
    //  protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
    //  {
    //      return new Ribbon1();
    //  }
    
    // 2. Create callback methods in the "Ribbon Callbacks" region of this class to handle user
    //    actions, such as clicking a button. Note: if you have exported this Ribbon from the Ribbon designer,
    //    move your code from the event handlers to the callback methods and modify the code to work with the
    //    Ribbon extensibility (RibbonX) programming model.
    
    // 3. Assign attributes to the control tags in the Ribbon XML file to identify the appropriate callback methods in your code.  
    
    // For more information, see the Ribbon XML documentation in the Visual Studio Tools for Office Help.
    
    
    namespace ExcelAddIn13
    {
        [ComVisible(true)]
        public class Ribbon1 : Office.IRibbonExtensibility
        {
            private Office.IRibbonUI ribbon;
    
            public Ribbon1()
            {
            }
    
            #region IRibbonExtensibility Members
    
            public string GetCustomUI(string ribbonID)
            {
                return GetResourceText("ExcelAddIn13.Ribbon1.xml");
            }
    
            #endregion
    
            #region Ribbon Callbacks
            //Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1
    
            public void Ribbon_Load(Office.IRibbonUI ribbonUI)
            {
                this.ribbon = ribbonUI;
            }
    
            #endregion
    
            #region Helpers
    
            private static string GetResourceText(string resourceName)
            {
                Assembly asm = Assembly.GetExecutingAssembly();
                string[] resourceNames = asm.GetManifestResourceNames();
                for (int i = 0; i < resourceNames.Length; ++i)
                {
                    if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
                        {
                            if (resourceReader != null)
                            {
                                return resourceReader.ReadToEnd();
                            }
                        }
                    }
                }
                return null;
            }
    
            #endregion
    
            public Bitmap GetImage(Office.IRibbonControl Control)
            {
                Bitmap result = null;
                switch (Control.Id)
                {
                    case "Test":
                        result = new Bitmap(@"C:\*******\XZ.bmp");
                        break;
                }
                return result;
            }
        }
    }
    

     

     

     

    I hope it can help you.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, December 20, 2011 7:16 AM
    Moderator