简体   繁体   English

用资源文件路径替换绝对文件路径

[英]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.我为现有软件 (Revit) 创建了一个加载项,我想在加载项的按钮中嵌入一个图像(我公司的徽标)。

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 .它工作得很好并且徽标显示正确,但是它需要计算机可以访问位于\\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.在家工作时,我们无法访问此服务器,因此 Revit 在启动时会引发错误。

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.因此,我尝试将FSElogo.png文件作为Resource添加到我的 VB.Net 项目中,然后尝试使用My.Resources访问图像,从而有效地消除了使用外部图像的需要。

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 .如果我不将Object转换为ImageSource ,我会得到implicit conversion from Object to Image ,我什至不确定我的ResourceManager是否真的返回FSElogo.png

What am I doing wrong here?我在这里做错了什么?

I am using the VS provided button with the .BackgroundImage property.我正在使用带有.BackgroundImage属性的 VS 提供的按钮。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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