OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "基本格式|*.txt;*.doc";
ofd.RestoreDirectory = false;
if (ofd.ShowDialog() == DialogResult.OK)
{
using (FileStream fs = new FileStream(ofd.FileName,FileMode.Open,FileAccess.Read))
{
StreamReader sr = new StreamReader(fs, Encoding.Default);
textBox1.Text = sr.ReadToEnd();
}
}
———————————————打开代码—————————————————
SaveFileDialog sfd = new SaveFileDialog();
sfd.RestoreDirectory = false;
sfd.Filter = "文本格式|*.txt";
if (sfd.ShowDialog() == DialogResult.OK)
{
using (FileStream fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write))
{
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
sw.Write(textBox1.Text);
sw.Flush();
sw.Close();
}
}
———————————————保存代码—————————————————
textBox1.Copy();
textBox1.Cut();
textBox1.Paste();
等等很多,详细你可以自己去看看 |