how can i change the color of numbers inside of the richtextbox?

poringgunner

Active member
Joined
Feb 23, 2014
Messages
42
Programming Experience
Beginner
it is possible to change the color of numbers in richtextbox?
example.. i have richtextbox that contains a text like this
"i have 50 words inside my richtextbox" //this is the first line of richtextbox.
"and i need only 30 of it" //this is the second line.



i want to change the color of number 50 and 30 to RED color.. but i dont know how to do it.
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
901
Location
Norway
Programming Experience
10+
I would use Regex class and its Matches method to find the numbers in text (gives you index and length of each match), then you use RichTextBox method Select(index,length) to select each number and set color with SelectionColor property. Regex expression \d+ should do it.
 

poringgunner

Active member
Joined
Feb 23, 2014
Messages
42
Programming Experience
Beginner
how about change the color of number into a 2 color like this

if the number is greater than or equal to 50.00 then its color will be RED.
if the number is less than 50.00 then it's color will be BLUE.

it is possible?
 
Top Bottom