# Circle randomly changes colours to red, yellow, orange

Page 1 of 1

## 6 Replies - 589 Views - Last Post: 16 July 2020 - 07:20 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=419505&amp;s=2291047895c245ba30d766ea1f693c15&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 albert003

Reputation: 38
• Posts: 869
• Joined: 15-December 14

# Circle randomly changes colours to red, yellow, orange

Posted 15 June 2020 - 10:55 AM

I have a new question for you guys. I wanted to put a smiley face on the screen with a smiley face which changes colour. I figured out how to draw circles but I cant figure out how to make it randomly change from orange,red and yellow.

I know how to make random numbers and strings in C#. I know how to draw an ellipse and make it into a circle. I just can't figure out how to make the circle randomly change colours.

This is how I would do it to show random numbers.
```using System.IO;
using System;

class Program
{
static void Main()
{
Random num = new Random();

for(int x = 0; x < 10; x++)
{
int a = num.Next(1,10);
int b = num.Next(1,10);
int c = num.Next(1,10);
Console.WriteLine(a+","+b+","+c);
}
}
}
```

Is This A Good Question/Topic? 0

## Replies To: Circle randomly changes colours to red, yellow, orange

### #2 DarenR

• D.I.C Lover

Reputation: 708
• Posts: 4,580
• Joined: 12-January 10

## Re: Circle randomly changes colours to red, yellow, orange

Posted 15 June 2020 - 11:00 AM

```Color randomColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));

BackColor = randomColor;
```

### #3 albert003

Reputation: 38
• Posts: 869
• Joined: 15-December 14

## Re: Circle randomly changes colours to red, yellow, orange

Posted 15 June 2020 - 12:32 PM

I found something similar to that online, it makes the whole back ground change random colours. My goal is to only make the circle which I've drawn change random colours only.

### #4 Skydiver

• Code herder

Reputation: 7453
• Posts: 25,095
• Joined: 05-May 12

## Re: Circle randomly changes colours to red, yellow, orange

Posted 15 June 2020 - 12:35 PM

Or if simply a randomly picking between red, orange, or yellow:
```var colors = new Color[] { Color.Red, Color.Orange, Color.Yellow };
var index = rnd.Next(colors.Length);
BackColor = colors[index];

```

### #5 Skydiver

• Code herder

Reputation: 7453
• Posts: 25,095
• Joined: 05-May 12

## Re: Circle randomly changes colours to red, yellow, orange

Posted 15 June 2020 - 12:42 PM

Amending post #4 due to not seeing post #3.
```var colors = new Color[] { Color.Red, Color.Orange, Color.Yellow };
var index = rnd.Next(colors.Length);
var randomColor = colors[index];
var brush = new SolidBrush(randomColor);
graphics.FillEllipse(brush, ...);

```

Just like when we were recommending that you pick up Programming Windows (5th Edition) by Charles Petzold when you were trying to learn Windows programming in C/C++, I recommend picking up the latest edition of Programming Windows by Charles Petzold with covers WinForms.

But if you are truly on the learning curve, I suggest skipping WinForms and going to straight to WPF. There are (many) bad habits that one can pickup while learning to program in WinForms that will have to unlearn when you are doing WPF. So might as well not even pick them up.

### #6 albert003

Reputation: 38
• Posts: 869
• Joined: 15-December 14

## Re: Circle randomly changes colours to red, yellow, orange

Posted 27 June 2020 - 10:32 PM

I haven't picked up the book, yet. I was laid off and haven't been able to find a job. I plan to buy the book once I land a job. I am trying not to pick up and bad habits by watching different video from different people explaining how to do C#. As well as using my googlefu to look up things.

### #7 KeyWiz

• D.I.C Regular

Reputation: 14
• Posts: 454
• Joined: 26-October 06

## Re: Circle randomly changes colours to red, yellow, orange

Posted 16 July 2020 - 07:20 PM

albert003, on 27 June 2020 - 11:32 PM, said:

I haven't picked up the book, yet. I was laid off and haven't been able to find a job. I plan to buy the book once I land a job. I am trying not to pick up and bad habits by watching different video from different people explaining how to do C#. As well as using my googlefu to look up things.

Look for Mosh Hamedani on Youtube or go to his site https://programmingwithmosh.com/ and take advantage of his free samples. Check out his C# courses.

This post has been edited by KeyWiz: 16 July 2020 - 07:22 PM