Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,690 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,316 people online right now. Registration is fast and FREE... Join Now!




Richtextbox: Coloring words knowing their index ?

 
Reply to this topicStart new topic

Richtextbox: Coloring words knowing their index ?, Coloring word in richtextbox

TheParadoX
post 4 Jun, 2008 - 07:51 AM
Post #1


New D.I.C Head

*
Joined: 4 Jun, 2008
Posts: 2

Hi !

I've been trying to color words in a RichTextBox in red. I made this and it works:

CODE

foreach (string sentence in splittedOriginalText)
{
richTextBox1.SelectionColor = Color.Black;
for (int i = 0; i < keywords.Length; i++)
{
if (keywords == sentence.ToLower())
{
richTextBox1.SelectionColor = Color.Red;
break;
}
}
richTextBox1.SelectedText = sentence + " ";
}



Now things have changed. I don't have any keywords to compare my words to, but only the index of the words that need to be colored. I've been trying, but somehow it won't work ... any idea to help me out here ?
User is offlineProfile CardPM

Go to the top of the page

TheParadoX
post 4 Jun, 2008 - 12:23 PM
Post #2


New D.I.C Head

*
Joined: 4 Jun, 2008
Posts: 2

OK I found a way:
CODE

            // Fill the textbox with the original sentence
            richTextBox1.Text = originalText[defectiveLineNumber].ToString();

            // Overwrite the words at their respective index
            for (int j = 1; j < currentArrayList.Count; j++)
            {
                String currentWord = ((WordAndIndex)currentArrayList[j]).myWord;
                int redIndex = ((WordAndIndex)currentArrayList[j]).myIndex;

                richTextBox1.SelectionStart = redIndex + 1;
                richTextBox1.SelectionLength = currentWord.Length;
                richTextBox1.SelectionColor = Color.Red;
                richTextBox1.SelectedText = currentWord;
            }
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:38AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month