RichTextBox - NewLine

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
I do quite a bit of formatting in some of my parsing controls, and mostly it is harmless, since the format strings are constants. the line:
VB.NET:
select * from MyTable;
is no different (intrinsically) from
VB.NET:
select *
from mytable
However, the latter of the two is more appealing to the eyes, so while debugging as well as while reformatting the "typed" commands into the editor, it looks more professional and clean. (I also output the formmatted commands to a debug file, but that is of no concern)

So anyway, there I am, I grab from a RichTextBox the command that was typed, (split on the ; character) and I execute in sequence each command, reformatting them and replacing the old with the new as it executes.
But here is the thing:
VB.NET:
Const SQLSELECT = "SELECT {0}" & vbCrLf & "FROM {1}" & vbCrLf

Now, I could use Environment.NewLine as well, but it too equals #13#10 as the standard MSDOS CR/LF line terminator format. Now enter's the brain dead RichTextBox and it strips the #13 character from the strings, so when I try this:
VB.NET:
RichText.SelectionStart = RichText.Text.IndexOf(MySqlString)
It doesn't work (-1 causing exception).

How can I tell the RichTextBox to not strip the carriage return for each new line? I've tried wordwrap = false, but it still keeps only the 10 not the 13.

Thanks
 
I'm not sure why the RTB does that or if there's a way to stop it, but have you considered NOT using CrLf as a line break and just using Lf? Modern Windows handles that gracefully in all cases I've seen.
 
I'm not sure why the RTB does that or if there's a way to stop it, but have you considered NOT using CrLf as a line break and just using Lf? Modern Windows handles that gracefully in all cases I've seen.

Not in notepad, which is where I most often edit my SQL for this. I resolved it in a better manner. My SqlParsing engine has a property .SQL which parses when Set, but Builds on Get. My Code was, shall we say, having some delays whenever I would select a different "results tab", it would try to do:
VB.NET:
SqlText.SelectionStart = SqlText.Text.IndexOf (Parser(i).SQL)
SqlText.ScrollToCaret

Well, that would s..l...o...w.. down the refresh because it was recalculating. I've done other searches around the web since I posted this, and it is a recurrent problem with the RTB, which comes to question how to export a MSDOS Cr/Lf Text file from the control, but i resolved the issue by simply utilizing the .Tag element of the individual TabPages. When each command is finished execution an event triggers to set the "status" icon of each tab. When I set the status to success I execute:
VB.NET:
TabPage.Tag = Parser(index).SQL.Replace(vbCr, "")

which then later on TabPage selection:
VB.NET:
SqlText.SelectionStart = SqlText.Text.IndexOf(TabCtrl.SelectedTab.Tag)
SqlText.ScrollToCaret

So, in the end, it is still frustrating that unlike other languages, they did not incorporate a "newlinechar" property within the RTB, but on the whole it is managable, and as well that glitch forced me to rethink how I was selecting the active command in the editor.

Thanks
 
Why exactly are you using a RichTextBox anyway? Are you using syntax highlighting? If not then you may as well just use a TextBox, which won't cull your Cr characters.
 
Why exactly are you using a RichTextBox anyway? Are you using syntax highlighting? If not then you may as well just use a TextBox, which won't cull your Cr characters.
Syntax Highlighting will be in eventually, but at the moment it affords me a bit more control, and a larger memory base for large files.

There were other reasons (can't remember though). I basically was trying to do something with the MultiLine TextBox and it wasn't doing what I wanted, so I switched to a RTB and it did. But that was months ago, so, *shrug*.
 
Back
Top