如何使用一种方法将随机骰子显示到12个图片框? [英] How to use one method to display random dice to 12 picture boxes?

查看:434
本文介绍了如何使用一种方法将随机骰子显示到12个图片框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有12个图片框,我正在调用一个名为ShowDice()的方法来显示骰子的图像。


这就是我正在做的事情:


- 为12个整数生成一个随机数

- 使用for循环计算正在显示的骰子:

展开 | 选择 | < span class =codeLinkonclick =WordWrap(this);> Wrap | 行号

解决方案

您可以通过几种不同的方式构建此代码。


I我认为我个人采取的方法是创建一个数组或图片集合牛和六个骰子图像的阵列或集合。然后你的任务基本上变成这样:

展开 | 选择 | Wrap | 行号


我将如何创建图片数组?框并将每个图片框分配给表单上的现有图片框。喜欢:


picDice1.Image = picBox [1] .Image;


展开 | 选择 | Wrap | 行号

I have 12 picture boxes and I am calling a method called ShowDice() to show the image of the dice.

Here is what I am doing exactly:

- Generate a random number for 12 integers
- Use a for loop to count which dice is being shown:

Expand|Select|Wrap|Line Numbers

解决方案

There are a couple of different ways you could structure this code.

I think that the path I would personally take is to create an array or collection of the picture boxes and an array or collection of the six dice images. Then your assignment basically becomes like this:

Expand|Select|Wrap|Line Numbers


How would I go about to create an array of picture boxes and assign each picture box to an existing picture box on the form. Like:

picDice1.Image = picBox[1].Image;


Expand|Select|Wrap|Line Numbers


这篇关于如何使用一种方法将随机骰子显示到12个图片框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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