• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C# Invalidate() only one object

tjmudder

Member
I'm writing a program for my class that draws a picture. The picture right now is of a house with a some windows and a door and a bird gif the flies by. I want the door to display a random color each time the program is loaded and it worked until I added the bird to fly by. Since the way to get the bird to animate I have to Invalidate() each time, this causes the door to change colors each Invalidate(). So I was wondering if there is a way to separate the the door so that it picks a random color once and keeps displaying that color while the bird flies by.
 
Well I just tried that and I cannot get it to work in my form load function method. Is there anyway you could give me any sample code?

Here is what I'm using:

Random r = new Random();
Color color = Color.FromArgb(r.Next(256), r.Next(256), r.Next(256));
Brush doorColor = new SolidBrush(color);
Graphics g = e.Graphics;
g.FillRectangle(doorColor, 230, 240, 40, 60);

Thanks!

 
So remove the code that generates the color and put that in your Constructor/Initialize function and reuse the same color everytime you call FillRectangle(...)
 
Back
Top