School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,078 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 4,796 people online right now. Registration is fast and FREE... Join Now!



[SOLVED] working with color in RichTextBox.

Page 1 of 1

[SOLVED] working with color in RichTextBox. Rate Topic: -----

#1 JohnorSky  Icon User is offline

  • D.I.C Head
  • PipPip
  • Group: Members
  • Posts: 136
  • Joined: 02-September 08


Dream Kudos: 0

Posted 10 April 2009 - 04:25 AM

[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:

  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 April 2009 - 06:04 PM

Was This Post Helpful? 0
  • +
  • -


#2 PsychoCoder  Icon User is offline

  • apt-get install DIC.bin
  • Icon
  • View blog
  • Group: Admins
  • Posts: 16,211
  • Joined: 26-July 07


Dream Kudos: 12400

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Posted 10 April 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 :)
Was This Post Helpful? 0
  • +
  • -

#3 JohnorSky  Icon User is offline

  • D.I.C Head
  • PipPip
  • Group: Members
  • Posts: 136
  • Joined: 02-September 08


Dream Kudos: 0

Posted 10 April 2009 - 05:47 PM

View PostPsychoCoder, on 10 Apr, 2009 - 06:47 AM, said:

@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 :)

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 April 2009 - 06:09 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month