8个图片,比如初始化8张图片分别是刘1,张2,李3,王4....... 当点击开始,启动一个Timer,这时轮流撤换刘1变成图A,其他不变,接着张2变成A,刘1变回刘1,其他不变,一直下去,直到用户点停止,timer.enalbe=false,轮到那里,那张图片就是A.在imer1_Tick中写如下代码:
PictureBox2.Image = this.ImageList1.Images [0];
PictureBox2.Image = WindowsApplication2.Properties.Resources.刘1;
PictureBox4.Image = this.ImageList1.Images[0];
PictureBox4.Image = WindowsApplication2.Properties.Resources.张2;代码是可以实现,但图片的转换没能在用户端表现,图片不能轮换!
PictureBox2.Image = this.ImageList1.Images [0];
PictureBox2.Image = WindowsApplication2.Properties.Resources.刘1;
PictureBox4.Image = this.ImageList1.Images[0];
PictureBox4.Image = WindowsApplication2.Properties.Resources.张2;代码是可以实现,但图片的转换没能在用户端表现,图片不能轮换!
PictureBox0.Image = this.ImageList1.ImagesA;
PictureBox7.Image = WindowsApplication2.Properties.Resources.X7; case 1:
PictureBox1.Image = this.ImageList1.ImagesA;
PictureBox0.Image = WindowsApplication2.Properties.Resources.刘1;case 2:
PictureBox2.Image = this.ImageList1.ImagesA;
PictureBox1.Image = WindowsApplication2.Properties.Resources.张2;.。。 最后
p++;
(if p==8) p=0;
你可以增加一变量,每次执行timer1_Tick时,该变量变化。
该变量的不同值对应不同的图片。
把你的代码修改下即可
switch (flat)
{
case 0:
PictureBox2.Image = this.ImageList1.Images[0]; PictureBox2.Image = WindowsApplication2.Properties.Resources.作废1;
break;
case 1:
PictureBox4.Image = this.ImageList1.Images[0];
PictureBox4.Image = WindowsApplication2.Properties.Resources.撤消;
break;
case 2: PictureBox5.Image = this.ImageList1.Images[0];
PictureBox5.Image = WindowsApplication2.Properties.Resources.撤消;
break;
case 3: PictureBox8.Image = this.ImageList1.Images[0];
PictureBox8.Image = WindowsApplication2.Properties.Resources.撤消;
break;
default:
flat++;
if (flat == 8)
{
flat = 0;
}
break;
}
上面代码执行后,图片不轮换。
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = !timer1.Enabled;
} int index = 1; private void timer1_Tick(object sender, EventArgs e)
{
PictureBox pb = this.Controls["pictureBox" + index] as PictureBox;
if (pb != null)
pb.Image = imageList1.Images[0];
switch (index)
{
case 1:
pictureBox8.Image = WindowsFormsApplication1.Properties.Resources.最后一张;
break;
case 2:
pictureBox1.Image = WindowsFormsApplication1.Properties.Resources.第一张;
break;
case 3:
pictureBox2.Image = WindowsFormsApplication1.Properties.Resources.第2张;
break;
case 4:
pictureBox3.Image = WindowsFormsApplication1.Properties.Resources.第3张;
break;
case 5:
pictureBox4.Image = WindowsFormsApplication1.Properties.Resources.第4张;
break;
case 6:
pictureBox5.Image = WindowsFormsApplication1.Properties.Resources.第5张;
break;
case 7:
pictureBox6.Image = WindowsFormsApplication1.Properties.Resources.第6张;
break;
case 8:
pictureBox7.Image = WindowsFormsApplication1.Properties.Resources.第7张;
break;
}
index++;
if (index > 8)
index = 1;
}
在timer_click事件里:
i++
if(i % 8 == 0)
{
轮换到第一张;
}
else if(i % 8 == 1)
{
轮换到第二张;
}
......
else if(i % 8 == 7)
{
轮换到第八张;
}
现在有一疑问,每个pictureBox都有轮转限制次数。如pictureBox8最多可以轮转3次,第一次轮转结束选择到pictureBox8 ,第三次和第5次也选到pictureBox8,那么以后的轮转,pictureBox8就不能参加轮转啦!
水平有限,有很多不完善的地方,你就当参考吧,自己再改改 private void button1_Click(object sender, EventArgs e)
{
int count = 0;
foreach (int i in pollingCount)
if (i == 0)
count++;
if (count == 8)
return;
timer1.Enabled = !timer1.Enabled;
if (!timer1.Enabled)
{
int i;
if (index == 1)
i = 7;
else
i = index - 2;
if (pollingCount[index - 1] > 0)
pollingCount[index - 1]--;
MessageBox.Show(index.ToString());
}
else
{
PictureBox pb = this.Controls["pictureBox" + (index == 1 ? 8 : index - 1)] as PictureBox;
if (pollingCount[index - 1] == 0 && pb != null)
pb.Visible = false;
}
} int index = 1;
int[] pollingCount = { 3, 4, 5, 4, 3, 5, 3, 5 }; private void timer1_Tick(object sender, EventArgs e)
{
PictureBox pb = this.Controls["pictureBox" + index] as PictureBox;
if (pb != null)
{
switch (index)
{
case 1:
pictureBox8.Image = WindowsFormsApplication1.Properties.Resources._219;
break;
case 2:
pictureBox1.Image = WindowsFormsApplication1.Properties.Resources._212;
break;
case 3:
pictureBox2.Image = WindowsFormsApplication1.Properties.Resources._213;
break;
case 4:
pictureBox3.Image = WindowsFormsApplication1.Properties.Resources._214;
break;
case 5:
pictureBox4.Image = WindowsFormsApplication1.Properties.Resources._215;
break;
case 6:
pictureBox5.Image = WindowsFormsApplication1.Properties.Resources._216;
break;
case 7:
pictureBox6.Image = WindowsFormsApplication1.Properties.Resources._217;
break;
case 8:
pictureBox7.Image = WindowsFormsApplication1.Properties.Resources._218;
break;
}
if (pb.Visible)
{
pb.Image = imageList1.Images[0];
index++;
if (index > 8)
index = 1;
}
else
{
while (!pb.Visible)
{
int count = 0;
foreach (int i in pollingCount)
if (i == 0)
count++;
if (count == 8)
return;
index++;
if (index > 8)
index = 1;
pb = this.Controls["pictureBox" + index] as PictureBox;
}
}
}
}