向功能区添加显示标准Outlook图标的按钮非常简单。将按钮的属性OfficeImageId设置为已知ID(例如“EncryptMessage”),您就完成了。有关可能值的完整列表,请参阅Office 2010 Add-In: Icons Gallery。
现在我的问题是,我可以在表单区域中实现同样的目的吗?我的意思是,添加一个PictureBox显示标准的Office图标?显然没有OfficeImageId属性,但也许有人知道一种解决方法。
答案 0 :(得分:3)
您提供的链接会转到Word 2010文档。我一直在使用带有功能区扩展的Excel 2007文档,显示所有内置图标(“其他下载部分”中的“2007 Office System加载项:图标库”。)在此工作簿中,您可以单击图标,VBA表格勇敢地显示了16x16和32x32图标。
这只是一个带有两个图片框的VBA表格。代码如下:
Sub OnAction(control As IRibbonControl, id As String, index As Integer)
If (control.Tag = "large") Then
id = Strings.Mid(id, 3)
End If
Dim form As New ControlInfoForm
form.nameX.Caption = "imageMso: " & id
Set form.Image1.Picture = Application.CommandBars.GetImageMso(id, 16, 16)
Set form.Image2.Picture = Application.CommandBars.GetImageMso(id, 32, 32)
form.Show
End Sub
我希望这可以帮助您获取图像。
答案 1 :(得分:0)
要使用this post on MSDN Forum完成以上文章,请访问VB.Net:
获取IPictureDisp
Dim MyMso As String = "FileFind"
Dim MyIPicture As stdole.IPictureDisp = Globals.ThisAddIn.Application.CommandBars.GetImageMso(MyMso, 16, 16)
扩展名转换为Drawing.Image
<System.Runtime.CompilerServices.Extension()>
Function GetImage(MyIPicture As stdole.IPictureDisp) As Drawing.Image
If CType(MyIPicture.Type, Integer) = 1 then
Return = Drawing.Image.FromHbitmap(MyIPicture.Handle, MyIPicture.hPal)
else
Throw New ArgumentException("Image not supported.")
End If
End Function
分配给控件
Dim MyButton As New Button
MyButton.Image = MyIPicture.GetImage
注意:我不知道为什么需要If CType(MyIPicture.Type, Integer) = 1
。任何见识都欢迎。另外,同一则帖子引用了System.Windows.Forms.AxHost
,但似乎没有在任何地方使用它?