[英]Replacing Absolute file path by Resource file path
我为现有软件 (Revit) 创建了一个加载项,我想在加载项的按钮中嵌入一个图像(我公司的徽标)。
这是我当前的代码:
'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
它工作得很好并且徽标显示正确,但是它需要计算机可以访问位于\\10.8.60.3
的服务器。 在家工作时,我们无法访问此服务器,因此 Revit 在启动时会引发错误。
因此,我尝试将FSElogo.png
文件作为Resource
添加到我的 VB.Net 项目中,然后尝试使用My.Resources
访问图像,从而有效地消除了使用外部图像的需要。
好吧,我无法让它工作。 我尝试将上面的代码替换为
MainButton.LargeImage = CType(My.Resources.ResourceManager.GetObject("FSElogo.png"), Windows.Media.ImageSource)
但它不起作用。 它不会引发错误,但按钮上不会显示任何图像。
如果我不将Object
转换为ImageSource
,我会得到implicit conversion from Object to Image
,我什至不确定我的ResourceManager
是否真的返回FSElogo.png
。
我在这里做错了什么?
我正在使用带有.BackgroundImage
属性的 VS 提供的按钮。 请注意,文件的扩展名不包含在资源标识符中。 如果这不起作用,您将必须准确解释如何将资源添加到项目中。
MainButton.BackgroundImage = My.Resources.FSElogo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.