user2897388
user2897388

Reputation: 85

How to save the text from richtextbox after changing the formats at runtime in windows application

I wrote some text in richtextbox at runtime and I changed the format of text.Suppose to Bold,Italic,changing the font verdana to Arial,changing the fontsize from 10 to 14 etc. when i clicked on save text is saving in .txt format and when I opened it after saving from richtextbox or normally,it is showing the default format which is in textfile(notepad) but not into the format which I changed at runtime. this is the code I used for saving the text in richtextbox.

        if (savefiledialog.ShowDialog() == DialogResult.OK)
        {
            try
            {
              richtextbox1.SaveFile(savefiledialog.FileName,RichTextBoxStreamType.PlainText);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

Upvotes: 0

Views: 2623

Answers (1)

Shell
Shell

Reputation: 6849

USE

RTP.SaveFile("D:\RtfFile.rtf", RichTextBoxStreamType.RichText);

When you are using PlainText that means application will not save text with formats. You assign the extension .rtf file must be saved in RichTextFormat.

UPDATE:

string fileName = string.Empty;

private void SaveFile()
{
    if (fileName ==string.Empty)
    {
        if (savefiledialog.ShowDialog() == DialogResult.OK)
            fileName = savefiledialog.FileName;
    }
    if (fileName != string.Empty)
    {
        try
        {
            richtextbox1.SaveFile(FileName,RichTextBoxStreamType.RichText);
        }
        catch (Exception ex)
        {
              MessageBox.Show(ex.Message);
        }
    }
}

Upvotes: 1

Related Questions