views:

20

answers:

2

In VB.Net, is it possible to highlight ALL instances of a phrase instead of only a single instance of it, for example:

    txtView.SelectionStart = txtView.Find("ERROR: Invalid command entered.")
    txtView.SelectionColor = Color.Red

This would highlight "ERROR: Invalid command entered.", however if my RichTextBox text is:

ERROR: Invalid command entered. < Only this line will highlight

ERROR: Invalid command entered.

ERROR: Invalid command entered.

Alternatively, is there a way I can simply colour the line when I write it to the RichTextBox? Thanks in advance!

A: 

Hi,

Have you considered putting into a loop, so counting how many needs to be highlighted and then looping the process until all have been highlighted?

James
A: 

Nope, there's is only one value for SelectionStart and SelectionLength. Yes, you can use the SelectionBackColor and SelectionColor properties to colorize the text that matches. You'll find sample code in my answer in this thread.

Hans Passant