Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

changing forecolor on a rich text box

Posted on 2014-02-28
2
514 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

861 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