Richtext box aplhabets coloring problem
If I enter on richtextbox any alphabets its show on different color, suppose if we enter 'A' or 'a' it show like green color and if we enter '1' it show like red color.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dharmendra SinghPosted Dec 4, 2013, 12:26 AM
my code is
internal void HighlightPhrase(RichTextBox box, string word, Color color)
{
box.SuspendLayout();
int pos = box.SelectionStart;
string s = box.Text;
int ix = 0;
while (true)
{
int jx = s.IndexOf(phrase, ix, StringComparison.CurrentCultureIgnoreCase);
if (jx < 0) break;
box.SelectionStart = jx;
box.SelectionLength = phrase.Length + 2;
box.SelectionColor = color;
ix = jx + 1;
}
box.SelectionStart = pos;
box.SelectionLength = 0;
box.ResumeLayout();
}
Sanjay KumarPosted Dec 3, 2013, 7:12 AM
http://stackoverflow.com/questions/13220856/how-to-use-multi-color-in-richtextbox
http://www.dotnetperls.com/richtextbox
http://www.codeproject.com/Articles/37668/Multiple-Colored-Texts-in-RichTextBox-using-C