Home All Groups Group Topic Archive Search About

vb.net richtextbox selectionstart coloring

Author
17 Aug 2006 12:52 PM
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

Author
17 Aug 2006 4:39 PM
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.

<marf***@yahoo.com> wrote in message
news:1155819165.641097.265250@p79g2000cwp.googlegroups.com...
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
Author
17 Aug 2006 9:55 PM
marfi95
Thanks.


Siva M wrote:
Show quoteHide quote
> 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.
>
> <marf***@yahoo.com> wrote in message
> news:1155819165.641097.265250@p79g2000cwp.googlegroups.com...
> 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