首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

想请问关于windowsform中timer控件使用的有关问题?小弟我想让timer来控制三个以下button循环改变颜色,希望帮忙?初学希望给给代码,非常感谢

2012-07-31 
各位高手想请教关于windowsform中timer控件使用的问题?我想让timer来控制三个以上button循环改变颜色,希望

各位高手想请教关于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--;        }
[解决办法]
源码已发

热点排行