部署Outlook加载项-没有资源/图像

时间:2018-09-07 09:19:01

标签: vb.net outlook vsto outlook-addin

我正在尝试部署我写的一个加载项,但是它找不到相关的资源-即功能区的图像。

我的GetImage函数是这样的:

    Dim path As String = AppDomain.CurrentDomain.BaseDirectory
    System.Windows.Forms.MessageBox.Show(path)
    path = path.Substring(0, path.LastIndexOf("\bin")) + "\Resources\" + imageName
    Return New Drawing.Bitmap(path)

它失败的原因似乎是AppDomain.CurrentDomain.BaseDirectory为C:\Users\MZE\AppData\Local\Apps\2.0\4RZKJG5Q.XVT\72NBJ1XY.1QH\andsoon。因此,出于某种原因,图像不会作为资源推出。我通过Visual Studio中的项目属性添加资源对话框添加了它们。 我还尝试过将构建设置为资源,然后将其复制到Visual Studio的图像属性中。

任何提示,我将不胜感激。

1 个答案:

答案 0 :(得分:0)

确保添加到项目中的图像位于解决方案的“资源”部分。

resource menu

检查图像的项目文件夹结构。

project tree

为您的GetImage函数尝试以下修订的过程。使用IntelliSense浏览到My.Resources.``resourceName下的图像。您不需要引用图像的路径。

Public Function GetImage(control As Office.IRibbonControl) As System.Drawing.Bitmap
    Try
        Select Case control.Id
            Case "btnYourButton1"
                Return My.Resources.Image1
            Case "btnYourButton2"
                Return My.Resources.Image2
            Case "btnYourButton3"
                Return My.Resources.Image3
            Case Else
                Return Nothing

        End Select

    Catch ex As Exception
        Return Nothing

    End Try

End Function

这里是资源对象的Microsoft reference