0

I'm developing a microsoft excel addin and added a button, but I need to add custom image to it. How to achieve that

  <button id="customButton1" label="myLabel" size="large" image="????" />
user1547968
  • 57
  • 2
  • 10

1 Answers1

1

Try using this code snippet in the code-behind:

customButton1.Image = new Bitmap("Image.jpg");

OR

customButton1.Image = Image.FromFile(@"C:\Image.jpg");

How to: Add Custom Icons to Toolbar and Menu Items

  1. Create a new class named ConvertImage. This class uses System.Forms.Axhost to convert an image file to an image type that can be applied to the menu item.

  2. Add a method to convert the icon file into an Image file by adding it to an ImageList. This code sends the Image file to the ConvertImage.Convert method you created and then returns the file to the caller.

Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
  • Thanks for the quick reply. I'm not using the visual designer, I'm using XML. So I have no reference to the button in my code behind – user1547968 Dec 25 '12 at 17:42
  • In my code behind I have nothing named custombutton1 ..... I'm using XML not visual designer – user1547968 Dec 25 '12 at 17:51
  • Thanks I got the image displayed but it seems that convert method make its pixels bigger which make the image blur, any solution for that – user1547968 Dec 26 '12 at 09:09