读书人

想请问关于windowsform中timer控件使用

发布时间: 2012-07-31 12:33:46 作者: rapoo

各位高手想请教关于windowsform中timer控件使用的问题?我想让timer来控制三个以上button循环改变颜色,希望帮忙?初学希望给给代码,非常感谢
功能:比如3个button,起初button的颜色是white,定时器记时5秒,5秒后button1的颜色变成red,之后定时器再次计时,5秒后第二个button也变成红色,依次下去3.4.5或者更多。求指教!!!!!谢谢~

[解决办法]

C# code
        Timer timer = new Timer();        List<Button> btns;        int i = 0;        public Form2()        {            InitializeComponent();                       btns = new List<Button>();            foreach (Control con in this.Controls)            {                if (con is Button)                {                    btns.Add(con as Button);                }            }            i = btns.Count;            timer.Interval = 5000;            timer.Tick += new EventHandler(timer_Tick);            timer.Start();                    }        void timer_Tick(object sender, EventArgs e)        {            //throw new NotImplementedException();            btns[i - 1].ForeColor = Color.Red;            i--;        }
[解决办法]
源码已发

读书人网 >C#

热点推荐