Click here to Skip to main content
16,009,407 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
I am creating a simple application which has the feature of text editor. The editor allows to create new documents, open existing documents/files and also edit them.
I am using a toolbar and a rich text box.
The toolbar has the following buttons/Options:
1. Create new document
2. Open existing document.
3. Save
4. Save As
5. Cut
6. Copy
7. Paste
8. Undo
9. Redo
10. Alignment (left, right and center)
11. Font size
12. Font Style(which shows the drop down list of all the fonts available)
13. Bold
14. Italic
15. Underline

I have completed much of these tasks. But I am unable to open a document in rich text box and save & save As functionality along with the font size and font type.

Please help me if possible.
Thanks in advance.
Posted

1 solution

for loading the file content you can use the code specified below

FileStream fStream = new FileStream("c:\\myfile.txt", FileMode.Open);
richTextBox1.Selection.Load(fStream, DataFormats.Text);


for saving the content you can use the code specified below

TextRange range;
FileStream fStream;
range = new TextRange(richTB.Document.ContentStart, richTB.Document.ContentEnd);
fStream = new FileStream("c:\\myfilenew.txt", FileMode.Create);
range.Save(fStream, DataFormats.Text);
fStream.Close(); 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900