如何将图片加载到随机图片框上 [英] How to load a picture onto a random picturebox

查看:73
本文介绍了如何将图片加载到随机图片框上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Visual C#开发一个应用程序,该应用程序的一部分由一个表单组成,该表单具有10个图片框和一个组合框,该框允许用户选择将图片加载到图片框的人(播放器或播放器)或计算机).现在,如果用户选择-player选项,则他/她可以单击图片框来加载图片,但是如果用户选择-computer选项,则应该将图片加载到随机图片框上.
如何制作将图片加载到随机图片框的代码?
代码示例会有所帮助..

谢谢....

i am currently developing an application using visual c# and part of the application consists of a form that has 10 pictureboxes and a combobox that allows the user to select who to load the pictures in to the pictureboxes (its either the player or the computer). now if the user selects the -player option he/she can click on to the pictureboxes to load the pictures but if the user selects the -computer option then a picture is supposed to load on to a random picturebox.
how do i make the code to load a picture on to a random picturebox?
code samples would help..

THANKS IN ADVANCE....

推荐答案

您可以将所有图片框放入数组中.之后,您可以使用随机 [
You could put all the pictureboxes into an array. After that you can use Random[^] class to generate a random number between 0 and 9. Something like:
Random random = new Random();
int index = random.Next(0, 9); 


现在,根据随机数从数组中获取图片框,并在其中显示图片.


Now get the picturebox from the array based on the random number and show the picture in it.


这篇关于如何将图片加载到随机图片框上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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