Solved

changing forecolor on a rich text box

Posted on 2014-02-28
2
506 Views
Last Modified: 2014-03-03
hi - I want to update a rich text box with data that has some characters color changed from black to red. is this possible using a RTB? the application involves showing the user by a change in color that certain text values have changed from one pass of the data to the next pass.
if it's not possible with a RTB, is there another approach I can take?
what I'm doing now is below (it doesn't work):

for (int k = 1; k < tempReply[0] + 1; k++)
                        {
                            if (totalBytes++ < size)
                            {
                                if (oldVars[k] != tempReply[k + 1] && !firstTime)                               
                                    displayVars_TB.ForeColor =  Color.Red;                                                                
                                else
                                    displayVars_TB.ForeColor = Color.Black;

                                Application.DoEvents();
                                displayVars_TB.AppendText( tempReply[k].ToString("X2") + " ");
                                Application.DoEvents();
                            }
                            else
                                break;
                           
                        }

Open in new window


thanks,
0
Comment
Question by:jdcoburn
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39895825
Sure it's possible.

Just move your SelectionStart() to the end of the RichTextBox, set the SelectionColor(), then call AppendText():
            for (int k = 1; k < tempReply[0] + 1; k++)
            {
                if (totalBytes++ < size)
                {
                    displayVars_TB.SelectionStart = displayVars_TB.TextLength;
                    if (oldVars[k] != tempReply[k + 1] && !firstTime)
                        displayVars_TB.SelectionColor = Color.Red;
                    else
                        displayVars_TB.SelectionColor = Color.Black;
                    displayVars_TB.AppendText(tempReply[k].ToString("X2") + " ");
                    Application.DoEvents();
                }
                else
                    break;
            }

Open in new window

0
 

Author Closing Comment

by:jdcoburn
ID: 39902247
thank you, nicely done.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question