Adding images to context menus

S

Synapse

Hi,
I'm working on a VSTO 2005 SE add-in for Word 2007 that add items to the
context menu. My problem is that I didn't manage to add images to my new
context menu items.
Here's my code to add an item to the context menu (here, the "Text" context
menu) :

Dim myContextMenuItem As Office.CommandBar
Dim btn As Office.CommandBarButton
myContextMenuItem = app.CommandBars("Text")
btn = myContextMenuItem.FindControl(Office.MsoControlType.msoControlButton,
, Caption)
If (btn Is Nothing) Then
btn = myContextMenuItem.Controls.Add(Office.MsoControlType.msoControlButton,
, "", pos, True)
btn.Caption = Caption
btn.Tag = Caption
btn.Style = Office.MsoButtonStyle.msoButtonCaption
btn.Visible = False
End If

I guess I should use the Picture property. So I added the following line :
btn.Picture = GetImage("myImage")
Where GetImage is declared like this :

Public Function GetImage(ByVal imageName As String) As stdole.IPictureDisp
Dim bitmap As Bitmap
bitmap = My.Resources.ResourceManager.GetObject(imageName)
Return PictureConverter.ImageToPictureDisp(bitmap)
End Function

And PictureConverter is a friend class :
Friend Class PictureConverter
Inherits AxHost
Private Sub New()
MyBase.New(String.Empty)
End Sub

Public Shared Function ImageToPictureDisp( _
ByVal image As Image) As stdole.IPictureDisp
Return CType(GetIPictureDispFromPicture(image), _
stdole.IPictureDisp)
End Function

Public Shared Function IconToPictureDisp( _
ByVal icon As Icon) As stdole.IPictureDisp
Return ImageToPictureDisp(icon.ToBitmap())
End Function

Public Shared Function PictureDispToImage( _
ByVal picture As stdole.IPictureDisp) As Image
Return GetPictureFromIPicture(picture)
End Function

End Class

Unfortunately, this doesn't work. There's no crash, but there's no picture
in my context menu item.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top