Click here to Skip to main content
15,910,787 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i want to create multi color words in a line using c sharp.

i will explain clearly the line is

Order confirmation Id is :88899 Price : 222 BUY Symbol: ABB and Date :2001-01-01

the above line i need BUY is BLUE Color and symbol is ABB is Red Color.

and the above requirement is work on RichText box .

how to write a code in C sharp.


i am new to C sharp.

Thanks in Advance.


Thanks
Nagaa
Posted
Updated 8-Jul-11 8:11am
v2
Comments
Sergey Alexandrovich Kryukov 13-Jul-11 17:44pm    
Tag it! WPF, Forms, what?
--SA

In WinForms, it goes something like this:

C#
richTextBox.SelectionColor = Color.Black;
richTextBox.Appendtext("OrderConfirmation id is: 88899 Price : 222 ");
richTextBox.SelectionColor = Color.Blue;
richTextBox.AppendText("BUY ");
richTextBox.SelectionColor = Color.Black;
richTextBox.AppendText("Symbol: ");
richTextBox.SelectionColor = Color.Red;
richTextBox.AppendText("ABB ");
richTextBox.SelectionColor = Color.Black;
richTextBox.AppendText("and Date :201-01-01");


If you're doing the psuedo richtext in Silverlight or WPF, you can easily find out how to do it using google.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-Jul-11 22:06pm    
It will work, my 5, but there are more elegant solutions, please see my answer.
--SA
It kind of sounds that you actually would like to use a DataGridView - so maybe this would help: Color DataGridView Cells Based On Data[^]

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Jul-11 17:46pm    
Interested idea (my 5), could be considered, but there is a more comprehensive way based on CodeProject articles.
Please see my solution.
--SA
Espen Harlinn 13-Jul-11 17:52pm    
Thank you, Sergey!
One of these components can help you:
WPF HTML Supported TextBlock[^],
A Professional HTML Renderer You Will Use[^].

Both works offer components based on HTML rendering, one for WPF, another for Forms. (Always tag UI library you want to use, don't force people in doing double work.)

—SA
 
Share this answer
 
Comments
Espen Harlinn 13-Jul-11 17:52pm    
How to deal with text, is usually pretty important, my 5
Sergey Alexandrovich Kryukov 13-Jul-11 18:17pm    
Thank you, Espen.
--SA
Using the class RichTextBox with do the trick, but there are more elegant solutions. They are based on embedded HTML renderer.

See these CodeProject articles:
A Professional HTML Renderer You Will Use[^] (Forms),
WPF HTML Supported TextBlock[^] (WPF).

—SA
 
Share this answer
 
Change the ForColor of the Text That you want to change or the textcolor
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900