Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a text editor with all the bells & Whistles.
has all the features like
Bold/ center/ left
zoom page to various sizes /
cut copy and paste.

however I have the following challenges

Opening
saving
Saving As

and then
getting the program to recognize the Rich Text File format.

Is there a way of saving to the rich Text format that
1: Saves the formatting of the text
2: Saves all the Bold/ underlined etc
3: then when reopening the format is opened with the saved formatting in the rich text format

Thank you

What I have tried:

VB
tthe usual save ect does not save it in anything but txt format even if i use a rich text box
Posted
Updated 29-Dec-22 5:38am

It depends on exactly what you do to save and restore the data: unless you export the data in RTF and import it back as RTF, then no formatting is preserved - TXT files do not have or understand any formatting, they are just a string of characters.

So look at what your saved files contain - it should look like this:
{\rtf1\ansi\deff0 {\fonttbl {\f0 Times New Roman;}}
\f0\fs60 Hello, World!
}
If it does, then look at what you do when you load it.

If it doesn't, then you need to use the debugger to find out what you are actually saving.

We can't do that for you - we have no access to your code or data files!
 
Share this answer
 
Comments
Member 11788039 29-Dec-22 10:13am    
This is what I have tried.

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim SaveDialog As New SaveFileDialog
SaveDialog.Filter = "Word Document (*.docx)|*.docx|Word 97-2003 Document (*.doc)|*.doc|Rich Text File (*.rtf)|*.txt|Plain Text (*.txt)|*.txt"
SaveDialog.ShowDialog()
If SaveDialog.FileName <> "" Then
Dim writer As New StreamWriter(SaveDialog.FileName)
Dim i As Integer = Asc("x") ' Convert to ASCII integer.
Dim x As Char = Chr(i) ' Convert ASCII integer to char.
writer.WriteLine(TextBox1.Text)
writer.Close()
End If
End Sub
OriginalGriff 29-Dec-22 11:35am    
And?
What do you expect me to do with that in isolation?
You are over complicating this. The RichTextBox control has it's own SaveFile[^] and LoadFile[^] methods. All you need to do is pass in the filepath.

A bunch of problems in so little code. The "save" code you've written completely ignores the actual RTF text, in the Rtf property, and instead only looks at the unformatted Text property.

You have extra code in snippet you posted that has absolutely nothing to do with saving the file, like converting "x" to ASCII and back to a Char? That code is meaningless and useless.

The RichTextBox will NOT handle Word documents in .docx or .doc format, so you can drop that stuff from your dialog box.

When using the built into the RichTextBox SaveFile and LoadFile methods, you don't need to create a StreamWriter.
 
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