Click here to Skip to main content
15,867,991 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want to change label font color randomly but i dont know how to do this task...so plz help me...............
Posted
Comments
Kenneth Haugland 8-Aug-12 0:54am    
WInForms or WPF? Use ColorFromRGB and a random function that creates values from 0 to 255... and your done
Sergey Alexandrovich Kryukov 8-Aug-12 0:56am    
Or ASP.NET, or...?
--SA
Shambhoo kumar 8-Aug-12 1:50am    
In Windows form
Shambhoo kumar 8-Aug-12 1:50am    
In windows application
Sergey Alexandrovich Kryukov 8-Aug-12 0:55am    
Why? What did you try? The problem is to simple to talk about. Read the documentation on Label, that's it. And System.Random. By the way, it's not possible to answer exactly, because you did not write exact type name of Label. There are different types under this name, which somewhat different members.
--SA

1 solution

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NewFurniture
{
    public partial class Test : Form
    {
        public Test()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (label1.ForeColor == Color.Black)
            {
                label1.ForeColor = Color.Red;
            }
            else if (label1.ForeColor == Color.Red)
            {
                label1.ForeColor = Color.Yellow;
            }
            else if (label1.ForeColor == Color.Yellow)
            {
                label1.ForeColor = Color.Green;
            }
            else
            {
                label1.ForeColor = Color.Black;
            }
        }

        private void Test_Load(object sender, EventArgs e)
        {
            timer1.Interval = 500;
            timer1.Start();
        }
    }
}
 
Share this answer
 
v2

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