在资源中编辑字符串

时间:2012-08-08 00:31:43

标签: c# .net winforms

如何编辑项目资源中的字符串?我在尝试时遇到此错误:

  

属性或索引器'Project.Properties.Resources.ExternalIp'无法分配 - 它是只读的

这就是我的所作所为:

Resources.ExternalIp = utf8.GetString(webClient.DownloadData("http://automation.whatismyip.com/n09230945.asp"));

2 个答案:

答案 0 :(得分:5)

Properties.Ressources只读(“已编译”),您必须使用Properties.Settings&将范围放到“用户”,这样它将是'ReadWrite'

Project.Properties.Settings.Default.ExternalIp = utf8.GetString(webClient.DownloadData("http://automation.whatismyip.com/n09230945.asp"));
Project.Properties.Settings.Default.Save();

enter image description here

答案 1 :(得分:4)

不应该写入资源;它们嵌入在可执行文件中,因此更改它们将涉及修改可执行文件。

从您的代码中看,您实际上需要application settings,而不是资源。