2
votes

Adding buttons showing standard Outlook icons to a Ribbon is pretty straightforward. Set the button's property OfficeImageId to a known ID (e.g. "EncryptMessage") and you're done. For a complete list of possible values see Office 2010 Add-In: Icons Gallery.

Now my question is, can i archieve the same thing in a Form Region? I mean, adding for example a PictureBox showing that standard Office icon? Obviously there is no OfficeImageId property, but perhaps someone knows a workaround.

2

2 Answers

4
votes

The link you provided goes to a Word 2010 document. I was using until now the Excel 2007 document with a ribbon extension showing all the built-in icons ("2007 Office System Add-In: Icons Gallery" in the "What others download section). In this Workbook you can click on an icon, and a VBA form shows the 16x16 and the 32x32 icon bravely.

It's just a VBA form with two picture boxes. The code is as follows:

   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

I hope that this helps you to get the image.

0
votes

To complete the above post with this post on MSDN Forum, here is a VB.Net answer:

Get the IPictureDisp

Dim MyMso As String = "FileFind"
Dim MyIPicture As stdole.IPictureDisp = Globals.ThisAddIn.Application.CommandBars.GetImageMso(MyMso, 16, 16)

Extension to convert into a 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

Assign to a control

Dim MyButton As New Button
MyButton.Image = MyIPicture.GetImage

Note: I have no idea why If CType(MyIPicture.Type, Integer) = 1 is required. Any insight is welcome.. ! Also, the same post refers to System.Windows.Forms.AxHost, but does not seem to be using it anywhere?