Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
How can i insert different letters with different color for each letter in textbox

means
"a" with one color
"b" with other color
Posted
Comments
joshrduncan2012 14-Nov-13 17:44pm    
What have you tried so far?
Sergey Alexandrovich Kryukov 14-Nov-13 18:05pm    
This is not as trivial as it may seem. I might need a hint myself. The problem is having really editable text. Please see my answer.
—SA
Masroor Ansari 18-Nov-13 15:57pm    
textbox for entering the text and label for displaying the text
♥…ЯҠ…♥ 14-Nov-13 23:26pm    
in c#? css? javascript?
Masroor Ansari 18-Nov-13 15:56pm    
c#

1 solution

Letters don't have colors, but HTML elements and fonts can have them. This is not possible with "regular" text box, you need to design or use very special control to do this. For a rudimentary code sample, please consider this:
HTML
<p contenteditable="true">This is an editable paragraph.</p>

(The sample is taken from http://www.w3schools.com/tags/att_global_contenteditable.asp[^].)

If click on this paragraph and you try to paste some colored/formatted fragment text, you will see that different colors and fonts will work. Try also this:
HTML
<p contenteditable="true">This is an editable paragraph. <span style="color:red">This text is colored.</span></p> 


I don't know your purpose. Want something more serious or practical? See how some JavaScript/HTML WYSIWYG editor work, like this one:
http://en.wikipedia.org/wiki/TinyMCE[^],
http://www.tinymce.com/[^].

Good luck,
—SA
 
Share this answer
 
v5
Comments
♥…ЯҠ…♥ 14-Nov-13 23:25pm    
Nice link... 5'ed
Sergey Alexandrovich Kryukov 14-Nov-13 23:32pm    
Thank you.
—SA

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