所以我有一个Windows窗体的DLL。有一个MainForm类创建一个ComponentResourceManager并访问存储在该表单的resx中的图像资源。如果我直接实例化那个类,那么一切都很快乐。从另一个类的窗体访问resx资源
如果我添加一个新的类到相同的命名空间(我只是将它添加到与MainForm类实际相同的.cs文件),并且尝试访问这些图像资源的方式与获取有关该资源的错误不同现有的文化。检查当前的线程文化(和UI文化),它们对于两者都是相同的。
是否有一些额外的箍我需要跳过通过从另一个类访问表单的资源?
示例代码
namespace myNamespace
{
public class extraClass
{
public extraClass()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(myForm));
System.Drawing.Image img = ((System.Drawing.Image)(resources.GetObject("StatusButton.Image")));
MessageBox.Show(img.ToString());
}
}
public class myForm : Form
{
public myForm()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(myForm));
System.Drawing.Image img = ((System.Drawing.Image)(resources.GetObject("StatusButton.Image")));
MessageBox.Show(img.ToString());
InitializeComponent();
}
}
}
在这个例子中实例化myForm会很乐意,但extraClass是不是和失败,有关无法找到资源在特定的文化错误&我才确保了资源是嵌入的(它是)。
Crazier and crazier。所以我很懒,并将我的新类extraClass添加到与myForm相同的cs文件中。结果是,即使我用一个空的构造函数将它分解为一个空类,导致主myForm在无法找到资源时也会出现相同的错误。我将尝试将extraClass移到或移到另一个文件。也许是因为我使用这个来自Python的DLL,而且Python的clr桥做了些什么? – greenhat