Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

changing color in Rich textbox while timer is on

$
0
0

I got a problem.I am giving colors to the text in Rich text box.When the timer is on ,all the text was turning to aqua color.But I need Different colors.Here is my 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
    };

        for (int i = 0; i < 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;
    }



P.Suhas


Viewing all articles
Browse latest Browse all 12583

Trending Articles