VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 306,784 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,618 people online right now. Registration is fast and FREE... Join Now!




[SOLVED] working with color in RichTextBox.

 

[SOLVED] working with color in RichTextBox.

JohnorSky

10 Apr, 2009 - 04:25 AM
Post #1

D.I.C Head
**

Joined: 2 Sep, 2008
Posts: 136


My Contributions
[SOLVED]

VB.NET: Problem: Trying to change the color of more than one of the same text within a RichTextBox. I found that I was able to achieve this by using the following code:

CODE
  Dim int1 As Integer = 0
        Dim search1 As String = "Boat"
        While int1 <> -1
            int1 = RichTextBox1.Text.IndexOf(search1, int1)
            If int1 <> -1 Then
                RichTextBox1.SelectionStart = int1
                RichTextBox1.SelectionLength = search1.Length
                RichTextBox1.SelectionColor = Color.Blue
                int1 = int1 + search1.Length
            End If
        End While


The above code searches for, and changes the color of all "Boat"s found in the RichTextBox.

There are a few problems, such as: If you were to go back to edit the RichTextBox and place your cursor in front of the, now blue word, "Boat" and type then all of your text would be blue.

Also, the text you wish to change the color of in the RichTextBox MUST be Exactly the same as: "Search1", aka "Boat", capital letters and all.

This post has been edited by JohnorSky: 10 Apr, 2009 - 06:04 PM

User is offlineProfile CardPM
+Quote Post


PsychoCoder

RE: [SOLVED] Working With Color In RichTextBox.

10 Apr, 2009 - 06:47 AM
Post #2

I Code, Therefore I am
Group Icon

Joined: 26 Jul, 2007
Posts: 14,919



Thanked: 517 times
Dream Kudos: 11525
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
@JohnorSky: Glad you were able to resolve your issue. For future reference please don't delete your post once the issue is resolved, someone may come in the future with the same issue and have nothing to look at smile.gif
User is offlineProfile CardPM
+Quote Post

JohnorSky

RE: [SOLVED] Working With Color In RichTextBox.

10 Apr, 2009 - 05:47 PM
Post #3

D.I.C Head
**

Joined: 2 Sep, 2008
Posts: 136


My Contributions
QUOTE(PsychoCoder @ 10 Apr, 2009 - 06:47 AM) *

@JohnorSky: Glad you were able to resolve your issue. For future reference please don't delete your post once the issue is resolved, someone may come in the future with the same issue and have nothing to look at smile.gif

They would be looking at a problem with no answer, because no one from this forum replied with an answer.

I reckon though, I could post the answer for people of the future. Here goes.

This post has been edited by JohnorSky: 10 Apr, 2009 - 06:09 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 07:44PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month