Serialcoder en Français Serialcoder in English
TEL : +33 (0)9 72 13 15 17

Windows Forms FAQ resources

22. Windows Forms RichTextBox

22.1 How can I create and save a RTF file?


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
          }     
     }