vb.net richtextbox selectionstart coloring

M

marfi95

Hi all,

I am trying to change the color of text that the user sees when they
are editing a richtextbox. This is the code I am using in the
TextChanged method of RichTextBox control.

Dim position As Integer = rtb.SelectionStart
rtb.Refresh()
rtb.SelectionStart = position

rtb.SelectionLength = 1
rtb.SelectionColor = Color.Red

This works starting with the 2nd character. The first character typed
is not red, but all typed characters after that are. Not sure why.


Any ideas ?

Thanks,
Mark
 
S

Siva M

That's because the event is fired only after the use typed the first
character (and for other types subsequently). Just call the TextChanged
event handler programmatically first (may be in the form load event).

By the way, the same result can be achieved just be setting the ForeColor fo
the RTB.

HTH.

Hi all,

I am trying to change the color of text that the user sees when they
are editing a richtextbox. This is the code I am using in the
TextChanged method of RichTextBox control.

Dim position As Integer = rtb.SelectionStart
rtb.Refresh()
rtb.SelectionStart = position

rtb.SelectionLength = 1
rtb.SelectionColor = Color.Red

This works starting with the 2nd character. The first character typed
is not red, but all typed characters after that are. Not sure why.


Any ideas ?

Thanks,
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top