none
ribbon xml image RRS feed

  • Question

  • how to add an image to the button which is created on xml ribbon? (adding an image using "image" attribute against button tag is not working for me)
    Tuesday, September 7, 2010 8:46 AM

Answers

  • Sruthi,

    check this out, below code works for you; i have modified ur snippet:

    Added GetImage attribute & Updated the function as well.

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load" >
     <commands>
     <command idMso="FileOpen" onAction="GetOpen"/> 
     </commands>
     <ribbon startFromScratch="false">
     <tabs>
      <tab id="tab1" label="Ribbon XML Demo" >
      <group id="group1" label="Demo Group">
       <button id="button1"   
       size="large"
       label="Open"
       getImage="GetImage"
       onAction="OpenBtn_Click" />
      </group>
      </tab>
     </tabs>
     </ribbon>
    </customUI>
    
    public Bitmap GetImage(IRibbonControl control)
        {
          switch (control.Id)
          {
            case "button1":
              {
                return new Bitmap(Properties.Resources.untitled);
              }        
          }
          return null;
    
        }
    
    • Marked as answer by Sruthi M Tuesday, September 7, 2010 10:08 AM
    Tuesday, September 7, 2010 9:59 AM

All replies

  • Hi Sruthi

    Could you please show us the Ribbon XML you've tried?

    Where would you be storing this graphics file?

    Are you creating a document-level customization or an application-level add-in?


    Cindy Meister, VSTO/Word MVP
    Tuesday, September 7, 2010 9:26 AM
    Moderator
  • Hi Sruthi M,

    For Custom Image, just like this:

     <button id="Button1" label="button1" showImage="true" imageMso="HappyFace"/>
    Best Regards,
    Amy Li
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Tuesday, September 7, 2010 9:33 AM
    Moderator
  • <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load" 
    loadImage="GetImage">
     <commands>
      <command idMso="FileOpen" onAction="GetOpen"/>  
     </commands>
     <ribbon startFromScratch="false">
      <tabs>
       <tab id="tab1" label="Ribbon XML Demo" >
        <group id="group1" label="Demo Group">
         <button id="button1"      
          size="large"
          label="Open"
          image ="untitled.bmp"
          onAction="OpenBtn_Click" />
        </group>
       </tab>
      </tabs>
     </ribbon>
    </customUI>
    
    
    public Bitmap GetImage(string imageName)
        {
          Assembly assembly = Assembly.GetExecutingAssembly();
          Stream stream = assembly.GetManifestResourceStream("SampleAddIn." + imageName);
    
          return new Bitmap(stream);
    
        }

    i am storing the image in the resources.resx

    i am creating the ribbon XML for Excel 2007 Add-in

     

    Tuesday, September 7, 2010 9:33 AM
  • hi Amy,

    i want to use my own custom image(i.e. using image attribute), not the one using imageMso attribute.

     

    Thanks

    Sruthi

    Tuesday, September 7, 2010 9:36 AM
  • hi Amy,

    i want to use my own custom image(i.e. using image attribute), not the one using imageMso attribute.

    Thanks

    Sruthi

    Tuesday, September 7, 2010 9:36 AM
  • Sruthi,

    check this out, below code works for you; i have modified ur snippet:

    Added GetImage attribute & Updated the function as well.

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load" >
     <commands>
     <command idMso="FileOpen" onAction="GetOpen"/> 
     </commands>
     <ribbon startFromScratch="false">
     <tabs>
      <tab id="tab1" label="Ribbon XML Demo" >
      <group id="group1" label="Demo Group">
       <button id="button1"   
       size="large"
       label="Open"
       getImage="GetImage"
       onAction="OpenBtn_Click" />
      </group>
      </tab>
     </tabs>
     </ribbon>
    </customUI>
    
    public Bitmap GetImage(IRibbonControl control)
        {
          switch (control.Id)
          {
            case "button1":
              {
                return new Bitmap(Properties.Resources.untitled);
              }        
          }
          return null;
    
        }
    
    • Marked as answer by Sruthi M Tuesday, September 7, 2010 10:08 AM
    Tuesday, September 7, 2010 9:59 AM
  • Its working, Thanks alot Aditya
    Tuesday, September 7, 2010 10:09 AM
  • Its working, Thanks alot Aditya
    Thursday, November 24, 2011 4:23 AM