Page 1 of 1
RichTextBox saving different file format problem
Posted: Mon Nov 24, 2014 3:41 pm
by Rhez
Hello (
again) CodeNStuff ,
I'll gonna give my problem directly, so here it is :
Whenever I open File that are made in RichTextBox it always added character that are irrelevant
What My Files look likes when I open it
Rollover to view spoiler{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\f0\fs17 Note Editor\par
\par
[Welcome to a new World]\par
\par
}
What I really want.
Rollover to view spoilerNote Editor
[Welcome to a new World]
.
Is there any solution for this thing ?
Re: RichTextBox saving different file format problem
Posted: Mon Nov 24, 2014 4:09 pm
by visualtech
Hey,
You first need to understand the
Rich Text Format; it stores the text in it's formatted way, i.e. how it looked (color, font, etc.).
Rich Text Box can parse the .rtf format saved by
WordPad on Windows and
TextEdit on a Mac.
It looks different from a normal text file as it stores the formatting of the test. You can parse and show it as a file in a richly formatted way.
Code: Select all'Use this
Dim s As String = richTextBox1.Text
Using writer As new StreamWriter("C:\Path\to\file.txt")
writer.WriterLine(s)
writer.Close()
End Using
'That was to save the file normally (without the formatting, like the way you wanted). Load it and display it back.
That was a simple approach, if I would've been in your place, I would've written a new Class Parser and a Writer for the the file format and then would've displayed it in the text box
+Rep if it helps ;)
Cheers! (PM me if you need more help in VB/C# or any other language)
Re: RichTextBox saving different file format problem
Posted: Mon Nov 24, 2014 4:47 pm
by Rhez
Ok .. So only .rtf and .txt file Richtextbox can be handle ?
Then how can I save my file in different format using RichTextBox ?
Re: RichTextBox saving different file format problem
Posted: Mon Nov 24, 2014 4:55 pm
by visualtech
.rtf - Formatting
.txt - Without formatting!
RichTextBox can show whatever you want! Its a text box after all. Any UTF-8/ANSI text is readable in a RichTextBox.
You can save it to virtually any file (format) but you'll loose the formatting. If you want the formatting, use .rtf else use .txt.
Re: RichTextBox saving different file format problem
Posted: Sat Nov 29, 2014 6:28 am
by Rhez
Ok . So can you suggest other than RichTextBox ?
I want to save my files in my own extension. And Read it as what should it be.
Re: RichTextBox saving different file format problem
Posted: Sat Nov 29, 2014 6:40 am
by visualtech
You can make one by inheriting RichTextBox of System.Windows.Controls