2011-06-07 60 views
6

大多數我讀過有關這個問題的答案的線程,你只需要訪問他們像這樣的:如何訪問C#項目中的嵌入式資源?

<MyProjectNamespace>.Properties.Resources.<MyResourceName> 

但在構建過程中,我有這樣的消息:

<MyProjectNamespace> does not contain a definition for 'Properties' 

似乎當您向項目添加資源時,類「屬性」通常由IDE自動生成。

事實上,我正在使用Eclipse,我並不真正知道如何添加資源,但我設法從Visual Studio生成.resx文件(我用它來設計我的Windows窗體)添加到Nant .build文件作爲'資源',以及我的位圖。然後,它確實嵌入資源,但我不能訪問它們...所以我怎麼能夠在我的應用程序(通常)中嵌入資源,並使用Eclipse + Emonic + Nant來訪問它們?

謝謝,

保羅。

回答

0

嘗試在System.Resources命名空間中使用ResourceManager。顯然,這取決於你試圖要檢索的有點,但我是這樣的:

ResourceManager.GetString("String1", resourceCulture); 
3

您應該創建一個ResourceManager實例中打開RESX文件是這樣的:

ResourceManager resources = new ResourceManager("<MyProjectNamespace>.Properties.Resources", typeof(<any type in the assembly>).Assembly); 
string myString = resources.GetString("myString"); 
Bitmap myBitmap = resources.GetObject("myBitmap") as Bitmap; 

如果他們是一種形式的資源,你也可以得到它們如下:

ResourceManager resources = new ResourceManager(typeof(Form1));