C#如何按顺序显示图像列表中的图像。 [英] C# how to display images from an imagelist in a sequential order.

查看:226
本文介绍了C#如何按顺序显示图像列表中的图像。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了清晰起见,我正在修改我之前发布的问题。我正在尝试编写一个代码,每隔两秒显示一个新图像。我编写了一个代码,可以从图像列表中随机获取图像并显示它们。但是,我需要它按顺序排列。做这个的最好方式是什么?



Ps。你可以告诉我,我是这个网站的新手,所以我为任何格式错误道歉。



我尝试过:



I am editing my previously posted question for clarity. I am trying to write a code where a new image is displayed every two seconds. I have written a code that randomly takes images from an imagelist and displays them. However, I need it to be in a sequential order. What is the best way to do this?

Ps. as you can probably tell, I am new to this site so I apologize for any formatting errors.

What I have tried:

private void timer1_Tick(object sender, EventArgs e)
        {
            Random mySchool;
            mySchool = new Random();  
            picCompanies.Image = this.imageList1.Images[mySchool.Next(4)]; 
        }

推荐答案

您使用与随机数相同的方式进行操作,现在只使用自己的每次使用时递增的数字(列表中必须至少有1个图像,或者您必须添加更多错误检查):

You do it in the same way as with a random number, only now you use your 'own' number that is incremented each time it is used (there has to be at least 1 image in the list or you have to add more error checking):
private int myNumber = 0;

private void timer1_Tick(object sender, EventArgs e)
{
    picCompanies.Image = this.imageList1.Images[myNumber];
    myNumber = myNumber + 1;
    if (myNumber >= imageList1.Images.Count) myNumber = 0;
}


这篇关于C#如何按顺序显示图像列表中的图像。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆