0

I'm working on a small project, and one of the components utilizes an animated dice. I've got the mechanics of the dice down, however, I wish to make the dice colour change each time it rolls.

As of now, I have to manually set the colour (e.g. pnl1.Backcolor = system.Drawing.color.Red).

I've already set up an array with the various different colours and intend to reference them randomly using the random number function, but my question is how can I refer to an item in the array in such a way that that makes the above mentioned pnl1.Backcolor match said colour?

I'm well aware I can't just use system.Drawing.color.Colours(1), so how might I go about this/what are some possible alternate options to an array?

Any and all help is massively appreciated and I do apologise if the way I've formatted this question is not in line with that which the website demands (I'm relatively new).

Thanks,

~ John

Jacob H
  • 2,455
  • 1
  • 12
  • 29
  • 1
    Is the array strictly typed as colors? Or as a string representing the color? This may be far easier for you with a `List (of ...)` instead of array. – Jacob H May 18 '18 at 19:52
  • Check this thread for an example of what I mean: https://stackoverflow.com/a/15069799/7948962 – Jacob H May 18 '18 at 19:54
  • I may consider that, but how may I implement that in to the above code? Thanks for the response! – John Naughton May 18 '18 at 21:08
  • A [similar question](https://stackoverflow.com/questions/50306394/randomize-3-colors/50306855#50306855), posted a few days ago. See if it can help. – Jimi May 18 '18 at 22:46

1 Answers1

0

I'm not sure whether you have a different panel for each side of the die or just one with a picture change, nevertheless, below is an example of something you could do. Change as needed (I'm assuming just one panel with color change - pnl1).

Dim PanColor() As Color = {Color.White, Color.Red, Color.Green, Color.Blue, Color.Purple, Color.Yellow}
    pnl1.BackColor = PanColor(put_random_number_here_0_to_5)
video.baba
  • 817
  • 2
  • 6
  • 11
  • As much as I appreciate the help, the syntax for changing the panel colour doesn't seem to coincide with that which you've included in the above code. For example, I can't dim something as a color, only console colour. – John Naughton May 22 '18 at 14:45
  • The above assumes you have: Imports System.Drawing, if not, add 'System.Drawing' to each 'color'. – video.baba May 22 '18 at 21:38