我写的winform背景动态变化没效果,望高手指教
private void Form2_Load(object sender, EventArgs e)
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(showbackground); //到达时间的时候执行事件;
// 设置引发时间的时间间隔 此处设置为1秒(1000毫秒)
aTimer.Interval = 100000;
aTimer.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
aTimer.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件;
}
public void showbackground(object source, System.Timers.ElapsedEventArgs e)
{
Form2 form = new Form2();
for (int i=0; i < 3; i++)
form.BackgroundImage = imageList1.Images[i];
}
}
}
------解决方案--------------------
aTimer.Interval = 100000;改成aTimer.Interval = 1000;
int i=0;
public void showbackground(object source, System.Timers.ElapsedEventArgs e)
{
Form2 form = new Form2();
for (int i=0; i < 3; i++)
form.BackgroundImage = imageList1.Images[i];
i++;
if(i==3) i=0;
}