本文介绍了如何循环图片框左移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作幻灯片图像,图像的方向向左。
I'm making a slideshow image and the direction of images is going left.
现在我的问题是如何使其成为无限循环?一旦出现最后一张图像,我想再次显示第一张图像,直到最后一张图像。我该怎么做?这是我的代码:
Now my problem is how can I make it an infinite loop? Once the last image appears, I want to show again the first image up to the last image again. How can I make this? Heres my code:
PictureBox[] clouds = new PictureBox[4]; public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { speed = 3; clouds[0] = pictureBox1; clouds[1] = pictureBox2; clouds[2] = pictureBox3; clouds[3] = pictureBox4; } private void timer1_Tick(object sender, EventArgs e) { for (int x = 0; x < 4; x++) { clouds[x].Left -= 10; if (clouds[x].Left == 0) { clouds[x].Left = +this.Width; } } }推荐答案
如果我理解的正确,您想要
If I understand you right, you want
0, 1, 2, 3, 0, 1, 2, 3, 0, ...序列。可以实现为
// x = 0 - start with x = 0 // - no condition (infinte loop) // x = (x + 1) %4 - modulo arithemetics: 0, 1, 2, 3, 0, 1, 2, 3, 0 .... for (int x = 0; ; x = (x + 1) % 4) { ... }通常情况下,对于 clouds [] 数组,我们可以摆脱幻数 4
In general case for clouds[] array we can get rid of magic number 4
for (int x = 0; ; x = (x + 1) % array.Length) { ... }更多推荐
如何循环图片框左移
发布评论