所以我有一個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