Reputation: 426
Am writing data in .rtf Format from a RichTextBox using (Text is color coded )
RichTextBox .SaveFile(path);
There is a 'Clear Text' button on the GUI on click of which clears the RichTextBox .
The problem arises when new data is printed on the RichTextBox instead of appending the data the RichTextBox .SaveFile(path)
method clears out the previous data and contains only the newly added data.
How can i append the data? StreamWriter is wrtitng the data in plain text i need it in .RTF.
Can anybody help me on this?
Upvotes: 2
Views: 1277
Reputation: 360
There is no option to append text to RTF file as you have already read from the comments.
What you can do, however, is use 2 RichEdit controls, one that reads the stream in using EM_STREAMIN
message (this will preserve the char format) and concatenate the new data to it. For the preservation of the char format of the new data from the other RichEdit control (colors,fonts etc), you have to use EM_GETCHARFORMAT
message on the selection of the new data you want to concatenate. And then, you need to use EM_SETCHARFORMAT
message with SCF_SELECTION OR SCF_WORD
to set the char format on the RichEdit control that will hold all data together. After that, use EM_REPLACESEL
message to concatenate all the data together. Finally, use EM_STREAMOUT
message to save all of the stream at one go.
Upvotes: 0
Reputation: 11763
Seems like saving from the rich text box overwrites the file. You can have a look at this or this for more info.
Some of the solutions suggested are saving to a different file, or reading, concatenating, and saving.
Upvotes: 1
Reputation: 1767
You can save the previous data in a variable, set the richTextBox's data to previous+new and then call the SaveFile method.
Upvotes: 1