C#流
在顶端加入using System.IO就可以使用流
StreamReder a = new StreamReder();//读取 前面什么都可以 = sr.ReadToEnd();//用法 StreamWriter a = new StreamWriter();//写入
窗体对话框
ColorDialog //选择颜色的对话框 FloderBrowserDialog //弹出一个对话框提示用户选择文件夹 FontDialog //弹出一个对话框提示用户选择字体或者字体颜色 OpenFileDialog //弹出一个对话框提示用户打开文件夹 SeveFileDialog //弹出一个对话框提示用户选择保存文件的位置 //字体用法 DialogResult a = fontDialog1.ShowDialog(); if (a == DialogResult.OK) { textBox1.Font = fontDialog1.Font; textBox1.ForeColor = fontDialog1.Color; } //打开用法 openFileDialog1.Filter = "文本文件|*.txt"; DialogResult a = openFileDialog1.ShowDialog(); if (a == DialogResult.OK) { string b = openFileDialog1.FileName; StreamReader sr = new StreamReader(b, Encoding.Default); textBox1.Text = sr.ReadToEnd(); } //保存用法 string f = ""; private void 保存SToolStripMenuItem_Click(object sender, EventArgs e) { if (f.Length <= 0) { saveFileDialog1.Filter = "文本文件|*.txt"; saveFileDialog1.FileName = "新建文本文档"; DialogResult a = saveFileDialog1.ShowDialog(); if (a == DialogResult.OK) { string s = saveFileDialog1.FileName; StreamWriter sr = new StreamWriter(s); sr.Write(textBox1.Text); sr.Flush(); f = s; } } else { StreamWriter sr = new StreamWriter(f); sr.Write(textBox1.Text); sr.Flush(); } } //另存为用法 saveFileDialog1.Filter = "文本文件|*.txt"; saveFileDialog1.FileName = "新建文本文档"; DialogResult a = saveFileDialog1.ShowDialog(); if (a == DialogResult.OK) { string s = saveFileDialog1.FileName; StreamWriter sr = new StreamWriter(s); sr.Write(textBox1.Text); sr.Flush(); }