Moshe Moshe - 1 year ago 112 Question

"Caret Position" in VB.NET for syntax highlighting

I'm trying to make a TextBox with syntax highlighting (for (HTML/CSS) in VB.NET 2008.

I figured that if I use RichTextBox.Find(), I can color specific text, but then I need to call RichTextBox.DeselectAll().

The problem is that the the cursor jumps to the beginning of the RTB.

I'm using WinForms.

Any ideas?

Answer Source

You can get and set the cursor position using the SelectionStart property.

Therefore, you can write,

Dim selStart As Integer = rtb.SelectionStart
'Do things
rtb.SelectionStart = selStart
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download