RichTextBox saving different file format problem

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
6 posts Page 1 of 1
Contributors
User avatar
Rhez
Member
Member
Posts: 30
Joined: Sat Jan 04, 2014 7:24 am

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 spoiler

Note Editor

[Welcome to a new World]

.
Is there any solution for this thing ?
User avatar
visualtech
VIP - Donator
VIP - Donator
Posts: 265
Joined: Sat Nov 19, 2011 2:19 pm

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)
Image
User avatar
Rhez
Member
Member
Posts: 30
Joined: Sat Jan 04, 2014 7:24 am

Ok .. So only .rtf and .txt file Richtextbox can be handle ?
Then how can I save my file in different format using RichTextBox ?
User avatar
visualtech
VIP - Donator
VIP - Donator
Posts: 265
Joined: Sat Nov 19, 2011 2:19 pm

.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.
Image
User avatar
Rhez
Member
Member
Posts: 30
Joined: Sat Jan 04, 2014 7:24 am

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.
User avatar
visualtech
VIP - Donator
VIP - Donator
Posts: 265
Joined: Sat Nov 19, 2011 2:19 pm

You can make one by inheriting RichTextBox of System.Windows.Controls
Image
6 posts Page 1 of 1
Return to “Coding Help & Support”