How to get the default resx file from a form?

穿精又带淫゛_ 提交于 2021-02-11 16:11:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!