用C#语言在Visual Studio中编程将文本框中的内容写入到txt文档
求各位大神指教,小弟新学在visual studio中用C#编程,遇到这个问题,希望大家指教一下下,谢啦如何用C#语言在Visual Studio中编程将文本框中的内容写入到txt文档,如图所示
visual studio c# textbox txt comboBox --------------------编程问答-------------------- 利用StreamWriter
参考 http://wangfeng5271.blog.163.com/blog/static/481744442011725102550568/
http://msdn.microsoft.com/zh-cn/library/system.io.streamwriter.writeline.aspx --------------------编程问答-------------------- 按钮click事件中:
private void button1_Click(object sender, EventArgs e)--------------------编程问答-------------------- System.IO.File.WriteAllLines("C:\\1.txt", new string[] { textBox1.Text, textBox2.Text, comboBox1.Text, comboBox2.Text }); --------------------编程问答-------------------- 谢谢了,小弟追问一下,能不能写成下图这种形式的
{
string data1 = this.textBox1.Text;
string data2 = this.textBox2.Text;
string data3 = this.textBox3.Text;
StreamWriter sw = new StreamWriter("test.txt");//写入到bin目录下的test.txt文件中
sw.WriteLine(data1 + ";" + data2 + ";" + data3);//以;隔开
sw.Close();//关闭流,才能写入txt
}
--------------------编程问答-------------------- string[] names = { "d1", "d2", "b1", "b2" };
string[] values = new string[] { textBox1.Text, textBox2.Text, comboBox1.Text, comboBox2.Text };
string[] query = names.Zip(value, (x, y) => x + "=" + y).ToArray();
System.IO.File.WriteAllLines("C:\\1.txt", query); --------------------编程问答--------------------
同上
补充:.NET技术 , C#