Reading string from resource file and editing it programmatically

前端 未结 1 1540
猫巷女王i
猫巷女王i 2020-12-11 08:32

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 programma

相关标签:
1条回答
  • 2020-12-11 09:00

    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:

    //Read
    String settingValue = Settings.Default.TestSetting;
    //Write
    Settings.Default.TestSetting = "newVal";
    //Write settings to disk
    Settings.Default.Save();
    
    0 讨论(0)
提交回复
热议问题