How do I add an image icon for custom button in outlook
Asked Answered
O

1

10

I have a custom button in outlook and I have to add image icon for the same button.

Ribbon XML is:

<button id="GoToAppConfiguration" 
    label="Application Configuration" 
    getImage="GetCustomImage" 
    onAction="GoToAppConfigurationClicked" 
    size="normal" />

I want to write ribbon callback method but how do I write the same and how do I use an image stored in a Resource folder under the Addin project.

Omit answered 27/4, 2012 at 11:57 Comment(1)
<button id="GoToAppConfiguration" label="Application Configuration" getImage="GetCustomImage" onAction="GoToAppConfigurationClicked" size="normal" />Omit
L
11

You just need to return a Bitmap from GetCustomImage. Here is a c# example, assuming you have added the BMP to your Project Resources.

public Bitmap GetCustomImage(Office.IRibbonControl control)
{
    return Properties.Resources.btnAppConfiguration_Image; // resource Bitmap
}
Laxation answered 27/4, 2012 at 12:32 Comment(5)
Doesn't the resource manager already give a copy of the image? It works fine if you specify Image instead of BitmapClitoris
@drake7707 - good catch! I edited the answer for simplicity and removed the unnecessary Bitmap instance creation. It appears you can return either Image or Bitmap for the getImage signature - IPictureDisp GetImage(IRibbonControl control). Outlook must handle the translation from Image to IPictureDisp internally. PictureDispConverter is not required for Ribbon XML customizations.Laxation
@SliverNinja Do you have a link which shows all of the callback definitions for Ribbon XML?Cardiganshire
I found it.. Scroll down towards the bottom to table 4. msdn.microsoft.com/en-us/library/aa722523.aspxCardiganshire
In order to make it, I had to add the method into the Ribbon classErratum

© 2022 - 2024 — McMap. All rights reserved.