C# 如何提取richtextbox中的特定内容并保存到一个文件里

2025-01-05 05:28:00
推荐回答(2个)
回答1:

方法一:
private void open_Click(object sender, EventArgs e)
{
OpenFileDialog opfd = new OpenFileDialog();
if (opfd.ShowDialog() == DialogResult.OK) {
//需要是固定的格式
richTextBox1.LoadFile(opfd.FileName,RichTextBoxStreamType.RichText);
}
}

private void save_Click(object sender, EventArgs e)
{
//保存
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == DialogResult.OK) {
richTextBox1.SaveFile(sfd.FileName);
}
}

方法二:Using system.IO;
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == DialogResult.OK) {
StreamWriter sw=new StreamWriter (sfd.FileName);
sw.Write(RichTextBox.Text);
}
}

回答2:

撒东西