Select text multiple?

  • Thread starter Thread starter Able
  • Start date Start date
A

Able

Dear friends

It exist a number of various apps displaying multiple selected text.
Normally every search function displays all hits as selected text in some
sort of text-control. Do somebody know how to manage this in VB.net and what
control to use? Is this possible with RichTextBox-control?

Regards Able
 
Hello Able,

yes you should be able to do this using the RichTextBox control. Here's a
simple example of how you can change the color of different words:

Dim text As String = "Hello how are you doing?"
Dim words() As String = {"how", "you"}

RichTextBox1.Text = text

For Each word As String In words
Dim startIndex As Integer = text.IndexOf(word)

If (startIndex >= 0) Then
RichTextBox1.SelectionStart = startIndex
RichTextBox1.SelectionLength = word.Length
RichTextBox1.SelectionColor = Color.Red
End If
Next


The RichTextBox control in .NET exposes a number of properties you can
change in addition to SelectionColor. If you need to change the background
color also, you'll need to talk to the native Win32 control as it's not
currently exposed in .NET. There are examples on how to do this on the web.
Here is one of them:
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=f98c4
4b4-0ba1-4cc5-a205-9aea2a7fbdf5

HTH

Antoine
Microsoft Visual Basic .NET

This reply is provided AS IS, without warranty (express or implied).

--------------------
 
Back
Top