任何方法使控件的位置在每次运行时改变,但不是随机的 [英] any way to make make position of a control to change at each run but not randomly

查看:82
本文介绍了任何方法使控件的位置在每次运行时改变,但不是随机的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让控件在每次运行时更改位置。不仅是随机的,而且可能是在点x,y和z。

is there a way to make a control to change location everytime it runs. not just randomly but perhaps at points x,y and z.

推荐答案

你知道那些你尝试选择两张相同图片的图片游戏吗?我写的但是现在我的朋友们现在的照片相同而且游戏不再有趣。任何方法都可以让照片在每次跑步时互相交换位置。



所以,你确实想要它随机。老实说,你做到了。你只是不希望实际位置是随机的。



假设你有三对图像(是的,我知道它有点简单 - 这个只是一个例子)。您设置了一个包含6个图像的数组:

"u know those picture games whereby you try to select two same pictures? i wrote it. but now my friends now where the same pictures are and the game is not fun anymore. is any way to make the pictures to swap positions with each other at every run."

So, you do want it randomly then. Honest, you do. You just don''t want the actual location to be random.

Assume you have three pairs of images (yes, I know it''s a bit simple - this is just an example). You set up an array of 6 Images:
private Image[] pics = new Image[6];

然后随机填充广告位:

You then fill the slots randomly:

private Random rand = new Random();
...
   SetImage(pics, Image1, rand.Next(0, 6));
   SetImage(pics, Image1, rand.Next(0, 6));
   SetImage(pics, Image2, rand.Next(0, 6));
   SetImage(pics, Image2, rand.Next(0, 6));
   SetImage(pics, Image3, rand.Next(0, 6));
   SetImage(pics, Image3, rand.Next(0, 6));
...
private void SetImage(Image[] pics, Image image, int index)
   {
   while (pics[index] != null)
      {
      index++;
      index %= 6;
      }
   pics[index] = image;
   }

然后按顺序使用pics数组在屏幕上显示图片。因为数组中图片的顺序是随机的,但位置不是,所以每次都会出现随机位置。

You then use the pics array in that order to show the pictures on the screen. Because the order of the pics in the array is random, but the locations aren''t, they appear in random positions each time.


这篇关于任何方法使控件的位置在每次运行时改变,但不是随机的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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