【发布时间】:2015-12-29 07:20:01
【问题描述】:
我想在 Windows 窗体中单击按钮在资源文件中添加数据。
我有一个带有 3 个文本框的窗体 -
text_box1:名称
text_box2:值
text_box3:评论
和一个名为 Save 的按钮。
我可以将数据保存在资源文件中,但不能以我想要的方式保存。它保存在下一行的每个值中,但我希望名称位于名称列下,值应位于列下,与注释相同。
我的按钮点击代码:
private void button1_Click(object sender, EventArgs e)
{
myMethod.Create(textBox1.Text, textBox2.Text, textBox3.Text);
}
将数据写入资源文件的代码:
public class myMethod
{
public static void Create(string myName, string myValue, string myComment)
{
ResXResourceWriter resxWriter;
try
{
resxWriter = new ResXResourceWriter(@"D:\Validator_Tool\resx\resx\myres.resx");
resxWriter.AddResource("Name", myName);
resxWriter.AddResource("Value",myValue);
resxWriter.AddResource("Comment", myComment);
resxWriter.Close();
}
catch (FileNotFoundException caught)
{
MessageBox.Show("Source: " + caught.Source + " Message: " + caught.Message);
}
}
}
请帮我将这 3 个值追加到一行而不是新行中。
【问题讨论】: