private void timer1_Tick(object sender, EventArgs e)
{
// Get the Graphics object of the form
Graphics graph = Graphics.FromHwnd(this.Handle);
// Generate a random number
Random rndNumber = new Random(DateTime.Now.Millisecond);
// Create a list of the colors of the .NET Framework
Color[] curColor =
{
Color.AliceBlue, Color.AntiqueWhite, Color.Aqua, Color.Aquamarine,
Color.Azure, Color.Beige, Color.Bisque, Color.Black,
Color.BlanchedAlmond, Color.Blue, Color.BlueViolet, Color.Brown,
Color.BurlyWood, Color.CadetBlue, Color.Chartreuse, Color.Chocolate,
Color.Coral, Color.CornflowerBlue, Color.Cornsilk, Color.Crimson,
Color.Cyan, Color.DarkBlue, Color.DarkCyan, Color.DarkGoldenrod,
Color.DarkGray, Color.DarkGreen, Color.DarkKhaki, Color.DarkMagenta,
Color.DarkOliveGreen, Color.DarkOrange, Color.DarkOrchid,
Color.DarkRed, Color.DarkSalmon, Color.DarkSeaGreen,
Color.DarkSlateBlue, Color.DarkSlateGray, Color.DarkTurquoise,
Color.DarkViolet, Color.DeepPink, Color.DeepSkyBlue, Color.DimGray,
Color.DodgerBlue, Color.Firebrick, Color.FloralWhite, Color.ForestGreen,
Color.Fuchsia, Color.Gainsboro, Color.GhostWhite, Color.Gold,
Color.Goldenrod, Color.Gray, Color.Green, Color.GreenYellow,
Color.Honeydew, Color.HotPink, Color.IndianRed, Color.Indigo,
Color.Ivory, Color.Khaki, Color.Lavender, Color.LavenderBlush,
Color.LawnGreen, Color.LemonChiffon, Color.LightBlue,
Color.LightCoral, Color.LightCyan, Color.LightGoldenrodYellow,
Color.LightGray, Color.LightGreen, Color.LightPink, Color.LightSalmon,
Color.LightSeaGreen, Color.LightSkyBlue, Color.LightSlateGray,
Color.LightSteelBlue, Color.LightYellow, Color.Lime, Color.LimeGreen,
Color.Linen, Color.Magenta, Color.Maroon, Color.MediumAquamarine,
Color.MediumBlue, Color.MediumOrchid, Color.MediumPurple,
Color.MediumSeaGreen, Color.MediumSlateBlue, Color.MediumSpringGreen,
Color.MediumTurquoise, Color.MediumVioletRed, Color.MidnightBlue,
Color.MintCream, Color.MistyRose, Color.Moccasin, Color.NavajoWhite,
Color.Navy, Color.OldLace, Color.Olive, Color.OliveDrab, Color.Orange,
Color.OrangeRed, Color.Orchid, Color.PaleGoldenrod, Color.PaleGreen,
Color.PaleTurquoise, Color.PaleVioletRed, Color.PapayaWhip,
Color.PeachPuff, Color.Peru, Color.Pink, Color.Plum, Color.PowderBlue,
Color.Purple, Color.Red, Color.RosyBrown, Color.RoyalBlue,
Color.SaddleBrown, Color.Salmon, Color.SandyBrown, Color.SeaGreen,
Color.SeaShell, Color.Sienna, Color.Silver, Color.SkyBlue,
Color.SlateBlue, Color.SlateGray, Color.Snow, Color.SpringGreen,
Color.SteelBlue, Color.Tan, Color.Teal, Color.Thistle, Color.Tomato,
Color.Transparent, Color.Turquoise, Color.Violet, Color.Wheat,
Color.White, Color.WhiteSmoke, Color.Yellow, Color.YellowGreen
};
// Create a list of 10 rectangles for each row
Rectangle[] row1 = new Rectangle[10];
Rectangle[] row2 = new Rectangle[10];
Rectangle[] row3 = new Rectangle[10];
Rectangle[] row4 = new Rectangle[10];
Rectangle[] row5 = new Rectangle[10];
Rectangle[] row6 = new Rectangle[10];
Rectangle[] row7 = new Rectangle[10];
Rectangle[] row8 = new Rectangle[10];
// Create the rectangles that will be drawn on the screen
for (int i = 0; i < 9; i++)
{
row1[i] = new Rectangle(i + (i * (Width / 10)), 0,
(Width - 36) / 10, Height / 8);
row2[i] = new Rectangle(i + (i * (Width / 10)), 4 + (Height / 8),
(Width - 36) / 10, Height / 8);
row3[i] = new Rectangle(i + (i * (Width / 10)), 8 + (2 * (Height / 8)),
(Width - 36) / 10, Height / 8);
row4[i] = new Rectangle(i + (i * (Width / 10)), 12 + (3 * (Height / 8)),
(Width - 36) / 10, Height / 8);
row5[i] = new Rectangle(i + (i * (Width / 10)), 16 + (4 * (Height / 8)),
(Width - 36) / 10, Height / 8);
row6[i] = new Rectangle(i + (i * (Width / 10)), 20 + (5 * (Height / 8)),
(Width - 36) / 10, Height / 8);
row7[i] = new Rectangle(i + (i * (Width / 10)), 24 + (6 * (Height / 8)),
(Width - 36) / 10, Height / 8);
row8[i] = new Rectangle(i + (i * (Width / 10)), 28 + (7 * (Height / 8)),
(Width - 36) / 10, Height / 8);
}
// Create the last rectangle of each row
Rectangle row1a = new Rectangle(9 + (9 * (Width / 10)),
0, ((Width - 36) / 10) - 2, Height / 8);
ectangle row2a = new Rectangle(9 + (9 * (Width / 10)),
4 + (Height / 8),
((Width - 36) / 10) - 2, Height / 8);
Rectangle row3a = new Rectangle(9 + (9 * (Width / 10)),
8 + (2 * (Height / 8)),
((Width - 36) / 10) - 2, Height / 8);
Rectangle row4a = new Rectangle(9 + (9 * (Width / 10)),
12 + (3 * (Height / 8)),
((Width - 36) / 10) - 2, Height / 8);
Rectangle row5a = new Rectangle(9 + (9 * (Width / 10)),
16 + (4 * (Height / 8)),
((Width - 36) / 10) - 2, Height / 8);
Rectangle row6a = new Rectangle(9 + (9 * (Width / 10)),
20 + (5 * (Height / 8)),
((Width - 36) / 10) - 2, Height / 8);
Rectangle row7a = new Rectangle(9 + (9 * (Width / 10)),
24 + (6 * (Height / 8)),
((Width - 36) / 10) - 2, Height / 8);
Rectangle row8a = new Rectangle(9 + (9 * (Width / 10)),
28 + (7 * (Height / 8)),
((Width - 36) / 10) - 2, Height / 8);
// Create a list of the hatch brushes of
// the .NET Framework using random colors
HatchBrush[] curBrush =
{
new HatchBrush(HatchStyle.BackwardDiagonal,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Cross,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.DarkDownwardDiagonal,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.DarkHorizontal,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.DarkUpwardDiagonal,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.DarkVertical,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.DashedDownwardDiagonal,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.DashedHorizontal,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.DashedUpwardDiagonal,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.DashedVertical,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.DashedVertical,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.DiagonalBrick,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.DiagonalCross,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Divot,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.DottedDiamond,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.DottedGrid,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.ForwardDiagonal,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Horizontal,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.HorizontalBrick,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.LargeCheckerBoard,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.LargeConfetti,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.LargeGrid,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.LightDownwardDiagonal,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.LightHorizontal,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.LightUpwardDiagonal,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.LightVertical,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Max,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Min,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.NarrowHorizontal,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.NarrowVertical,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.OutlinedDiamond,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Percent05,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Percent10,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Percent20,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Percent25,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Percent30,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Percent40,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Percent50,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Percent60,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Percent70,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Percent75,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Percent80,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Percent90,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Plaid,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)]),
new HatchBrush(HatchStyle.Percent05,
curColor[rndNumber.Next(curColor.Length)],
curColor[rndNumber.Next(curColor.Length)])
};
// Draw the rectangles to cover the screen
for (int i = 0; i < 9; i++)
{
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row1[i]);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row1[i]);
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row2[i]);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row2[i]);
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row3[i]);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row3[i]);
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row4[i]);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row4[i]);
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row5[i]);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row5[i]);
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row6[i]);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row6[i]);
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row7[i]);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row7[i]);
graph.FillRectangle(
curBrush[rndNumber.Next(curBrush.Length)], row8[i]);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row8[i]);
}
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row1a);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row1a);
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row2a);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row2a);
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row3a);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row3a);
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row4a);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row4a);
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row5a);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row5a);
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row6a);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row6a);
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row7a);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row7a);
graph.FillRectangle(curBrush[rndNumber.Next(curBrush.Length)], row8a);
graph.DrawRectangle(
new Pen(curBrush[rndNumber.Next(curBrush.Length)]), row8a);
}
|