单击下一步按钮时如何随机显示图像 [英] how to display images randomly when click Next button
本文介绍了单击下一步按钮时如何随机显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在单击下一步"按钮选项时随机显示图像.我创建了一个带有5个图片框的表单,如果我单击下一个btn,它将随机显示图片.
how to display images randomly when click Next button option. i created a form with 5 picturebox if i click next btn it will show pics randomly
推荐答案
这很难精确,因为您对应用程序的了解不多,以及如何存储图像,但假设它们位于文件夹中:
It''s difficult to be precise, wtihout knowing more about your application, and how you store your images, but assuming they are in a folder:
private Random rand = new Random();
private Image GetRandomImage( string myImageFolderPath )
{
string[] files = Directory.GetFiles(myImageFolderPath);
int i = rand.Next(files.Length);
return Image.FromFile(files[i]);
}
相应地命名您的图片(以image_1,image_2,image_3等结尾).然后使用随机对象将URL更改为ImageUrl:
Hi,
Name your pictures accordingly (ending with image_1, image_2, image_3, etc.). Then change the URL to the ImageUrl with a random object:
Random rand = new Random();
pictureBox.ImageUrl = "Your URL" + "\\image_" + rand.Next(1,6);
亲切的问候
Kind regards
这篇关于单击下一步按钮时如何随机显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文