简体   繁体   中英

Replacing Absolute file path by Resource file path

I created an add-in to an existing software (Revit) and I want to embed an image (my company's logo) in the add-in's button.

Here is my current code for it:

'Set the large image shown on button
        Dim uriImage As New Uri("\\10.8.60.3\Shared\REVIT\FSElogo.png")
        Dim largeImage As New BitmapImage(uriImage)
        MainButton.LargeImage = largeImage

It works pretty well and the logo is correctly displayed, however it requires the computer to have access to the server located at \\10.8.60.3 . When working from home, we do not have access to this server and Revit throws an error when starting because of it.

So I tried adding the FSElogo.png file to my VB.Net project as a Resource and then tried to use My.Resources to access the image, effectively removing the need for an external image to be used.

Well, I can't get it to work. I tried replacing the code above by

MainButton.LargeImage = CType(My.Resources.ResourceManager.GetObject("FSElogo.png"), Windows.Media.ImageSource)

But it doesn't work. It doesn't throw an error, but no image is displayed on the button.

If I don't cast my Object to an ImageSource I get an implicit conversion from Object to Image error, and I'm not even sure my ResourceManager is even really returning the object FSElogo.png .

What am I doing wrong here?

I am using the VS provided button with the .BackgroundImage property. Notice that the extension of the file is not included in the resource identifier. If this doesn't work, you will have to explain exactly how you added the resource to your project.

    MainButton.BackgroundImage = My.Resources.FSElogo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM