如何将工具栏图标放在outlook插件中。?

问题描述:

这里我创建Outlook插件2007年。我添加工具栏并在此工具栏上添加一个按钮。我想用按钮附加图标(按钮名称是导入),在这里我写了一个函数getimage()来设置按钮图片属性的图标。但是这里m没有得到图标与工具栏button.so请大家帮我解决这个问题为什么我不是用按钮让图标如何将工具栏图标放在outlook插件中。?

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; 
    } 

添加thisline的button.picture下面 button_1.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption;