如何循环图片框左移

编程入门 行业动态 更新时间:2024-10-27 14:20:56
本文介绍了如何循环图片框左移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在制作幻灯片图像,图像的方向向左。

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) { ... }

更多推荐

如何循环图片框左移

本文发布于:2023-11-29 19:13:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647368.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图片   框左移

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!