Question

I'm using a RichTextBox control in a .NET Windows Form application. I allow users to press the TAB key within the textbox itself. However when I save the .Text value in the textbox it will show up like this:

"This[]is[a]tab[]test[]"

Where each time the user pressed TAB, it shows up as unrecognized characters in the .Text property.

What's going on here?

Example Screenshot:
enter image description here

Was it helpful?

Solution 2

I ended up searching for all instances of a 'TAB' character being pressed and replacing it with a '\t' and that worked:

Dim tabString = Convert.ToChar("    ") //This is the [] string
RichTextBox.Text = RichTextBox.Text.Replace(tabString, "     ")

Not the best solution, still do not understand why the RichTextBox isn't picking up on the TAB key automatically but it works for now.

OTHER TIPS

In the Intermediate Window:

?RichTextBox1.Text results in "Hi mint " even though with AcceptTab=True we think it should be "Hi[TAB Key]Mint"

?RichTextBox1.Rtf results in

"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}  \viewkind4\uc1\pard\f0\fs17 Hi\tab mint\tab\par  }"

Here is the trick I believe your looking for:

RichTextBox1.SaveFile("C:\abc.txt", RichTextBoxStreamType.UnicodePlainText)

There is a property in RichTextBox called "AcceptsTab", just set this property as "true".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top