To add pic on the customized button on the outlook

P

Puneet

I created an imagelist object and added image to that object.
Now the picture property of button accepts Stdole.IPictureDisp type. So to convert the imge type returned from the imagelist object i used

using System;
using System.Drawing;
using System.Windows.Forms;
using stdole;
public class MyHost : AxHost
{
public MyHost(): base("59EE46BA-677D-4d20-BF10-8D8067CB8B33")
{
}
public new static IPictureDisp GettIPictureDispFromPicture(Image image)
{
return (IPictureDisp)AxHost.GetIPictureDispFromPicture(image);
}
}

this class

and here is the coding to add the pic

ImagelistForm ObjIlf = new ImagelistForm();
//To add the "Archive to Sugar" button in the outlook
Office.CommandBarButton button_1 =(Office.CommandBarButton)newToolBar.Controls.Add(1, missing, missing, missing, missing);
button_1.Style = (Microsoft.Office.Core.MsoButtonStyle)Office.MsoButtonStyle. msoButtonCaption;
button_1.Caption = "Archive to Sugar";
button_1.Tag = "ArchivetoSugar";
button_1.piPicture = MyHost.GettIPictureDispFromPicture(ObjIlf.imageListbuttons.I mages[1]);
if (this.archieve == null)
{
this.archieve = button_1;
archieve.Click += new Office._CommandBarButtonEvents_ClickEventHandler(archieveCli ck);
}

But the pic is not shown on the button
If any body knows th tricks than plz reply as soon as possible as i have already spent lots of time on that
 
K

Ken Slovak - [MVP - Outlook]

Does the image meet with the CommandBarButton specs of 32x32 with 8-bit
color as a BMP type file? Where are you adding the button, in an Explorer or
an Inspector?

If this is for a WordMail Inspector then you can't use AxHost or
IPictureDisp objects or the Picture or Mask properties of the buttons. You
can't pass IPictureDisp objects across process boundaries. In that case
you'd have to use the PasteFace method and take your composite image from
the Clipboard.

Is button_1.piPicture =
MyHost.GettIPictureDispFromPicture(ObjIlf.imageListbuttons.I mages[1]);
a typo? The property is Picture, not piPicture.

If this is for an Inspector then you should not add UI in the NewInspector
event, where the Inspector is a weak object reference. Wait until the first
Inspector.Activate event to add any UI. In many cases Inspector.CommandBars
is not fully valid in NewInspector.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top