One way to do this is to use the RichTextBox.SaveFile method.
private void button1_Click(object sender, System.EventArgs e)
{
// Create a SaveFileDialog & initialize the RTF extension
SaveFileDialog saveFile1 = new SaveFileDialog();
saveFile1.DefaultExt = '*.rtf';
saveFile1.Filter = 'RTF Files|*.rtf';
// get a file name from the user
if (saveFile1.ShowDialog() == DialogResult.OK)
{
// Save the RTF contents of the RichTextBox control that
// was dragged onto the Window Form and populated somehow
richTextBox1.SaveFile(saveFile1.FileName,
RichTextBoxStreamType.RichText); //use to save RTF tags in file
//RichTextBoxStreamType.PlainText);//use to save plain text in file
}
}
Share with