c# - Rich textbox is not changing back color for text when timer starts -


i got problem.i giving colors text in rich text box.when timer on ,all text turning aqua color.but need different colors.here code

    private void form1_load_1(object sender, eventargs e)     {         //richtextbox1.font = new font("consolas", 18f, fontstyle.bold);         richtextbox1.backcolor = color.aliceblue;         string[] words = { "sachin tendulkas(40)", "virendra sehwag(35)", "dhoni", "ramesh", "saurov ganguly(39)", "venkatesh prasad(44)" };         color[] colors =                {     color.aqua,     color.cadetblue,     color.cornsilk,     color.gold,     color.hotpink,     color.lavender,     color.moccasin     };          (int = 0; < words.length; i++)         {             string word = words[i];             color color = colors[i];             {                 richtextbox1.selectionbackcolor = color;                 richtextbox1.appendtext(word);                 //richtextbox1.selectionbackcolor = color.aliceblue;                 richtextbox1.appendtext(" ");             }         }         timer1.start();     }      private void timer1_tick(object sender, eventargs e)     {         string str1 = richtextbox1.text;         str1 = str1.substring(1) + str1.substring(0, 1);         richtextbox1.text = str1;     } 

this line:

richtextbox1.text = str1; 

replaces of existing formatting.

you have select range of characters , replaces valid rtf string.

i suspect want tick event (no error checking):

private void timer1_tick(object sender, eventargs e) {   richtextbox1.select(0, 1);   string rtf = richtextbox1.selectedrtf;   richtextbox1.selectedtext = string.empty;   richtextbox1.select(richtextbox1.text.length, 0);   richtextbox1.selectedrtf = rtf; } 

Comments