本文介绍了从资源文件读取字符串和编程编辑它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我如何读取字符串资源文件?我已经尝试过这一点,但我无法得到的值。编辑它后,我不能做任何事情。我怎么可以在以后programmaticaly编辑?我想用字符串,我从文本到编辑其值。 大会总成= this.GetType()汇编。 经理=新的ResourceManager(StringResources.Strings,装配); 值= manager.GetString(名称); 有关改变其值我试图做到这一点,但它给了我一个错误不包含定义当前。我尝试这些在windows窗体 Application.Current.Resources [名称] =ABCD; 请给我提前 的建议由于解决方案 您不能编辑资源字符串。如果你想存储一些字符串,你可以改变编程,你应该使用一个配置文件,或者,甚至更好的用户或应用程序设置(即实际上是配置文件周围的包装)。 这是你不能在运行时改变资源字符串究其原因,是因为资源被编译成可执行文件。如果您反向工程编译的* .exe或* .dll文件,你可以看到你的代码串。编辑已编译的可执行文件是不是一个好主意(除非你试图破解它),但是当你尝试从可执行代码做到这一点,它只是简单的不可能的,因为在执行过程中的文件被锁定。 您可以阅读更多有关用户设置的 MSDN上。 你应该检查出的链接,因为它包含有截图为如何通过GUI设置您设置的详细说明。 在简单地说,你右击你的项目 - >属性 - >设置。现在,你会看到一个表格,您可以添加,编辑和删除用户设置。一旦您创建了用户设置,你可以使用它是这样的: //读取字符串settingValue = Settings.Default .TestSetting; //将 Settings.Default.TestSetting =的newval; //将设置保存到磁盘 Settings.Default.Save(); How can I read string resource file? I have tried this already but I couldn't get the value. For editing it later I couldn't do anything. How can I edit it later programmaticaly? I want to edit its value with a string that I get from textbox. Assembly assembly = this.GetType().Assembly;manager = new ResourceManager("StringResources.Strings", assembly);value = manager.GetString("Name");For changing its value I tried to do this but it gives me an error does not contain a definition for Current. I try these in windows form.Application.Current.Resources["Name"] = "abcd";Please give me an adviceThanks in advance 解决方案 You cannot edit a resource string. If you want to store some string that you can alter programatically you should use a configuration file, or, even better user or app settings (that are actually a wrapper around the configuration file).The reason that you can't change a resource string at runtime, is because the resource is compiled into your executable. If you reverse engineer the compiled *.exe or *.dll file, you can actually see your string in the code. Editing an already compiled executable file is never a good idea (unless you're trying to hack it), but when you try to do it from the executables code, it just plain impossible, as the file is locked during execution.You can read more about user settings on MSDN.You should check out the link, as it contains detailed instructions with screenshots as to how to set your settings through GUI.In brief, you right click your project->Properties->Settings. Now, you'll see a table where you can add, edit and remove user settings. Once you create a user setting you can use it like this://ReadString settingValue = Settings.Default.TestSetting;//WriteSettings.Default.TestSetting = "newVal";//Write settings to diskSettings.Default.Save(); 这篇关于从资源文件读取字符串和编程编辑它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 23:32