要实现pictureBox变换图片,设了断点看实行没啥问题,可看到的图片总是不变,为什么?
private void timer1_Tick(object sender, EventArgs e)
{
if (i == 1)
{
this.pictureBox1.Image =img[0] ;
i = 0;
}
else
{
this.pictureBox1.Image = img[1];
} i++;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (i == 1)
{
this.pictureBox1.Image =img[0] ;
i = 0;
}
else
{
this.pictureBox1.Image = img[1];
} i++;
}
解决方案 »
- 新手求救!c#输出窗口一直保持一个状态,添加新的控件都无用
- 请教一下如何构建上下级关联树形节点
- word页复制时出错,系统win2003
- 用Twain获取扫描仪图像,如何得到性能的各个值?急用
- 如何将字符数组转为String类型?
- 删除新闻和其相关图片,麻烦大家近来帮忙
- findwindow的问题?
- 不能登陆数据库?
- 如何在DataGrid上新增一列,这列在绑定的DataView里没有
- 各位老大!有没有用C#写的浏览器的程序?
- <TextBlock Text="{Binding Title}" />里的Text="{Binding Title}"是什么意思?
- 利用upd协议中的receive是总是错误
{
if (i == 1)
{
this.pictureBox1.Image =img[0] ;
i = 0;
}
else
{
this.pictureBox1.Image = img[1];
i = 1;
} }I交替以后,才可以吧
timer1.Enable的属性设置正确了没有?
timer1.Interval的时间设置为多少》?
2、其次就是你这段代码有问题假设i=1;执行
if (i == 1)
{
this.pictureBox1.Image =img[0] ;
i = 0;
}执行完了后,i++;i变成2,之后将会一直执行else里面的代码。。就是
this.pictureBox1.Image = img[1];
正确代码如下 private void timer1_Tick(object sender, EventArgs e)
{
if (i == 1)
{
this.pictureBox1.Image =img[0] ;
i = 0;
}
else
{
this.pictureBox1.Image = img[1];
i=1;
}
}
你看你的代码,不知道你的i初始值是什么,如果i=1的话,那么就会加载img[0],同时i=0,然后再次执行i++,i又为1了,那样下次还是加载img[0],img[1]永远得不到加载
private void timer1_Tick(object sender, EventArgs e)
{
if (index < imageList1.Images.Count - 1)
{
index++;
}
else
{
index = 0;
}
pictureBox1.Image = imageList1.Images[index];
}
随机random
picturebox.Image=Image.Form(rnd.Next(0,9)+".jpg"));