JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Saving and Loading RTF Files from and to Rich Text Boxes

You've gotten feedback from a user of your word processor, SuperDuperTextPro, and it seems they've written a 600-page novel with the program and now find there's no way to save it to disk. Can you help? They will keep their computer on until they hear from you.

You use the SaveFile method to save the text in a rich text box to disk, and the LoadFile method to read it back. And doing so is easy. To see how this works, take a look at the RichTextBoxes example on the CD-ROM; when you click the "Save and restore text", the text in the bottom rich text box (RichText3) is written to a rich text file, text.rtf, then read back in and stored in the top rich text box (RichText1):

Private Sub Button6_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button6.Click
End Sub

You can see this at work in Figure 5.12. That's all it takes-now we've written RTF to a file, and read it back in.

Figure 5.12: Saving rich text to a file and reading it back in.

Many word processors, such as Microsoft Word, support RTF files, so you can now write formatted text files that such word processors can read in and use.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor