2
Answers

How do you convert Plain Text to Rich Text problem free?

Photo of Stephen

Stephen

18y
6k
1
Hi, I'm currently writing a simple text editor in Visual C# 2005 Express which has some syntax highlighting for the MIPS Assembly language. I use a RichTextBox control to color the keywords and it works so far, except for one problem: when I copy text from (or load in) a plain text source file, the text (using Currier New) is out of alignment in some places. In other words, the text is lined up correctly if you view it in notepad, but in my program it seems that anywhere there are tab characters everything is out of whack. Curiously, if you copy the same text into Word Pad, it has the same problem, even if you choose a non-variable width font like Currier New. I guess what I'm trying to say is copying a plain text file into RTF editors seems to have some formatting issues, where the plaintext source file looks fine in notepad but a bit out of whack in something like Word Pad. I'd just use a normal TextBox control (which works fine) if I didn't need to color the keywords! So the real question is, how can I get Rich Text formatting to behave more like plain text formatting, at least as far as tabs and alignment are concerned?

Answers (2)

0
Photo of John
NA 8 0 18y
Ok, how does this translate to the RTB control?

With properties such as Font, ForeColer, BackColor etc. It's simply a matter of selecting the text you want (best done via REGEX) then changing the back and forecolors.

So I think your question is how do I filter incoming ASCII data?  Use REGEX
How do I apply the formatting to the data? Use the RTB.properties and methods.
0
Photo of John
NA 8 0 18y

In the font world there are two types of fonts proportional and non-proportional.  Try using Courier New, it is a non-proportional font.

Your other issues, that of knowing the differences between RTF and regular text files is summed up with this statement: "They are both standards-based ways to present data to the end user."  

Here's the RTF standard.

http://www.microsoft.com/downloads/details.aspx?FamilyID=e5b8ebc2-6ad6-49f0-8c90-e4f763e3f04f&DisplayLang=en 

A Rich Text Box supports this standard.

TextBox is a more simple "standard" that has much less overhead.  I don't know the standard for Textbox support but feel it must be pretty simply  ASCII characters with very simple font control.