问题
For example I have got these files:
Form1.Designer.cs
Form1.en-US.resx
Form1.resx
I want to access the Form1.resx file.
This is what I tried, but it returns me - based on the language of the operating system - the resx file. But I always want to have that form1.resx file no matter the language of the operating system.
ResourceManager rm = new System.Resources.ResourceManager(typeof(Form1));
ResourceManager rm = new System.Resources.ResourceManager("TranslatedText.Form1",typeof(Form1).Assembly);
Do I overlook something?
回答1:
I think you can always access it like a class.
<Name of resx file>.<name of the key added>
eg: If you a resource file called Resource1 and a string value testkey, then this can be accessed as
Resource1.testkey
Here is a link that might help you. It has code to retrieve a value from resource files yb giving in the location of the file.
Hope this helps.
回答2:
I have found myself an answer.
This is what I did, and it works :)
ResourceManager rm = new System.Resources.ResourceManager(typeof(Form1));
Gets the resources of the Form1 class.
string defaultCultureValue = rm.GetString("label1.Text", CultureInfo.CreateSpecificCulture(""));
This will try to get a specific culture, which there is't, so it will get the created default culture which is the Form1.resx file.
来源:https://stackoverflow.com/questions/22191911/how-to-get-the-default-resx-file-from-a-form