且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用默认模式保存文本文件?

更新时间:2023-02-20 10:34:37

通常文本文件无法存储格式化的字符串.

Hi, in general text files cannot store formatted strings.

格式化的字符串可以以RTF格式,Word Doc,HTML等格式存储.

Formatted strings can be stored in Rich Text Format, Word Doc, HTML,..

在您的代码中,您试图将文件另存为文本文件.而是尝试将其保存为RTF格式.

In your code you are trying to save the file as text file. Instead try to save it as rich text format (rtf ).

私有void saveToolStripMenuItem_Click(对象发送者,EventArgs e ){字符串fnane ="; saveFileDialog1.FileName ="; saveFileDialog1.Filter =富文本格式| * .rtf |所有文件| *.*"; foreach(tabControl1.SelectedTab.Controls中的控件rhh){如果(rhh是RichTextBox){如果(saveFileDialog1.ShowDialog()!= DialogResult.Cancel){fnane = saveFileDialog1.FileName; (rhh为RichTextBox).SaveFile(fnane,RichTextBoxStreamType.RichText); }}}

private void saveToolStripMenuItem_Click(object sender, EventArgs e) { string fnane = ""; saveFileDialog1.FileName = ""; saveFileDialog1.Filter = "Rich Tex Format|*.rtf|All files|*.*"; foreach (Control rhh in tabControl1.SelectedTab.Controls) { if (rhh is RichTextBox) { if (saveFileDialog1.ShowDialog()!= DialogResult.Cancel) { fnane = saveFileDialog1.FileName; (rhh as RichTextBox).SaveFile(fnane, RichTextBoxStreamType.RichText); } } }