在这里,我创建了2007年的Outlook插件。在这里,我添加了工具栏,并在工具栏上添加了一个按钮。我想要附加图标与按钮(按钮名称是导入),这里我写了一个函数getimage()来设置图标的按钮图片attribute.but这里我没有得到图标与工具栏button.so请大家帮助我解决这个问题,为什么我不得到图标与按钮
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;
}发布于 2013-05-17 18:40:10
在button.picture button_1.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption;下面添加以下行
https://stackoverflow.com/questions/16606707
复制相似问题