0

here i m creating the Outlook addin for 2007.here i add tool bar and add one button on this tool bar. i want attach icon with button(button name is import)., here i write a function getimage() to set icon for button picture attribute.but here m not getting icon with tool bar button.so please guys help me to out this issue why i m not getting Icon with button

private void AddToolbar()
    {

        if (newToolBar == null)
        {
            Office.CommandBars cmdBars =
                this.Application.ActiveExplorer().CommandBars;
            newToolBar = cmdBars.Add("NewToolBar",
                Office.MsoBarPosition.msoBarTop, false, true);
        }
        try
        {                
            Office.CommandBarButton button_1 =
                (Office.CommandBarButton)newToolBar.Controls
                .Add(1, missing, missing, missing, missing);
            button_1.Style = Office
                .MsoButtonStyle.msoButtonCaption;
            button_1.Caption = "Import";
            button_1.Tag = "Button1";



      button_1.Picture = getImage();

            if (this.firstButton == null)
            {
                this.firstButton = button_1;
                firstButton.Click += new Office.
                    _CommandBarButtonEvents_ClickEventHandler
                    (ButtonClick);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

class ConvertImage : System.Windows.Forms.AxHost
{
    private ConvertImage()
        : base(null)
    {
    }

    public static stdole.IPictureDisp Convert
        (System.Drawing.Image image)
    {
        return (stdole.IPictureDisp)System.
            Windows.Forms.AxHost
            .GetIPictureDispFromPicture(image);
    }
}

    private stdole.IPictureDisp getImage()
    {
        stdole.IPictureDisp tempImage = null;
        try
        {
            System.Drawing.Icon newIcon =
                Properties.Resources.recruit_logo;

            ImageList newImageList = new ImageList();
            newImageList.Images.Add(newIcon);
            tempImage = ConvertImage.Convert(newImageList.Images[0]);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        return tempImage;
    }
4

1 回答 1

0

在 button.picture button_1.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption 下方添加这一行;

于 2013-05-17T10:40:09.807 回答