(続き)
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load" loadImage="GetImage">
GetImageは以下のようにコーディングしてみました.
Public Function GetImage(ByVal imageName As String) As stdole.IPictureDisp
Const resourcePrefix As String = "WordAddin1."
Dim resourceName As String = resourcePrefix + imageName
Dim asm As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
Dim resourceNames() As String = asm.GetManifestResourceNames()
For i As Integer = 0 To resourceNames.Length - 1
If String.Compare(resourceName, resourceNames(i), StringComparison.OrdinalIgnoreCase) = 0 Then
If Right(resourceName, 4) = ".ico" Then
Dim icon As System.Drawing.Icon = New System.Drawing.Icon(asm.GetManifestResourceStream(resourceNames(i)))
Return PictureConverter.IconToPictureDisp(icon)
End If
End If
Next
Return Nothing
End Function
Const resourcePrefix As String = "WordAddin1."
Dim resourceName As String = resourcePrefix + imageName
Dim asm As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
Dim resourceNames() As String = asm.GetManifestResourceNames()
For i As Integer = 0 To resourceNames.Length - 1
If String.Compare(resourceName, resourceNames(i), StringComparison.OrdinalIgnoreCase) = 0 Then
If Right(resourceName, 4) = ".ico" Then
Dim icon As System.Drawing.Icon = New System.Drawing.Icon(asm.GetManifestResourceStream(resourceNames(i)))
Return PictureConverter.IconToPictureDisp(icon)
End If
End If
Next
Return Nothing
End Function
' Copied from following URL
' http://msdn.microsoft.com/ja-JP/aa338202.aspx
' AxHost --> System.Windows.Forms.AxHost
' Image --> System.Drawing.Image
' Icon --> System.Drawing.Icon
Friend Class PictureConverter
Inherits System.Windows.Forms.AxHost
Private Sub New()
MyBase.New(String.Empty)
End Sub
' http://msdn.microsoft.com/ja-JP/aa338202.aspx
' AxHost --> System.Windows.Forms.AxHost
' Image --> System.Drawing.Image
' Icon --> System.Drawing.Icon
Friend Class PictureConverter
Inherits System.Windows.Forms.AxHost
Private Sub New()
MyBase.New(String.Empty)
End Sub
Public Shared Function ImageToPictureDisp( _
ByVal image As System.Drawing.Image) As stdole.IPictureDisp
Return CType(GetIPictureDispFromPicture(image), _
stdole.IPictureDisp)
End Function
ByVal image As System.Drawing.Image) As stdole.IPictureDisp
Return CType(GetIPictureDispFromPicture(image), _
stdole.IPictureDisp)
End Function
Public Shared Function IconToPictureDisp( _
ByVal icon As System.Drawing.Icon) As stdole.IPictureDisp
Return ImageToPictureDisp(icon.ToBitmap())
End Function
ByVal icon As System.Drawing.Icon) As stdole.IPictureDisp
Return ImageToPictureDisp(icon.ToBitmap())
End Function
Public Shared Function PictureDispToImage( _
ByVal picture As stdole.IPictureDisp) As System.Drawing.Image
Return GetPictureFromIPicture(picture)
End Function
End Class
ByVal picture As stdole.IPictureDisp) As System.Drawing.Image
Return GetPictureFromIPicture(picture)
End Function
End Class
ともかく今までVBAばかりやってきて、まともに.NET VBを知らないので間違いもあるかもしれませんがご容赦ください.でも以上の手順でなんとか.dotmの場合と同じくVS2010のデバッガからWord2010を立ち上げて同じリボンを表示するようにできました.
さらに後日談ですが、これだけ一生懸命やったのですが、円高の影響もあってかお客様からプロジェクトは今年度は中止という連絡が来てしまいました.作った成果品をみんなSubversionに登録しましたが、こんど再開と言われたときVBのノウハウなどの記憶が頭に残っているか心配です.1年前に自分が何をどう考えていたかなんて覚えていませんよね.