C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-21-2008, 06:25 PM   #1
Registered User
 
Join Date: Dec 2007
Posts: 380
Search for words and change their color

If you have a richTextBox that contains these words.
What is the best/good way to do, if I want to change the color of the word "hello" to Ex: red.
Is there any searchfunction that can select multiple words etc...
I am trying to find a way to do this.


one two three hello
five hello
hello
Coding is offline   Reply With Quote
Old 03-26-2008, 07:22 AM   #2
Registered User
 
Join Date: Jun 2003
Posts: 90
I have a complete mind block on the actual code, but know the process... (!)

Put all the richTextBox contents in to a string, replace search term in string with the word itself and the formatting needed.

ie. (but not actually this! This example replaces the term wanted with a bolded word in html format)

Code:
public static void ReplaceText(string myTerm)
{
  string myString = richTextBox1.Text;
  myString.Replace(myTerm, "<b>"+myTerm+"<\b>");
  richTextBox1.Text = myString;
}
Then you can just feed in whatever term you want ("hello") like so:

Code:
ReplaceText("hello");
I'm bored, needed to do something random...
__________________
He who asks is a fool for five minutes, but he who does not ask remains a fool forever.

The fool wonders, the wise man asks. - Benjamin Disraeli

There are no foolish questions and no man becomes a fool until he has stopped asking questions. Charles Steinmetz

Last edited by DanFraser; 03-26-2008 at 07:24 AM.
DanFraser is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Binary Search Trees Part III Prelude A Brief History of Cprogramming.com 16 10-02-2004 03:00 PM
adding a function to a program trippedwire C++ Programming 9 09-30-2004 12:35 PM
Trying to find a way to change color Vanished C++ Programming 2 11-24-2002 11:16 AM
trying to make change from the price of the item and the amount given. please help!!! tobyman C++ Programming 2 09-04-2001 02:12 PM
is there a way to set a pixel or change font color? Flikm C++ Programming 9 09-01-2001 01:24 PM


All times are GMT -6. The time now is 06:11 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22