Self Generated Colored Rectangle

Multi color Rectangle is generated at every tick of timer.I have used a timer
to generate color rectangles randomly


//In timer's Tick Event
Random rnd = new Random();
//width of screen
int x1 = rnd.Next(ClientSize.Width);
int x2 = rnd.Next(ClientSize.Width);
//height of screen
int y1 = rnd.Next(ClientSize.Height);
int y2 = rnd.Next(ClientSize.Height);
//color in RGB format
Color clr = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
Graphics g = CreateGraphics();
//Fills Rectangle with different color
g.FillRectangle(new SolidBrush(clr), Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2 - x1), Math.Abs(y2 - y1));
//Releases all resources
g.Dispose();
//In Button Click Event
{
timer1.Start();
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: