我有一系列颜色,我想在C#中为for循环中的标签指定颜色。我怎么能这样做?

时间:2016-05-27 13:59:09

标签: c# winforms colors

Color[] brickcolor = new Color[] { Color.Red, Color.Orange, Color.Pink, Color.Purple, Color.Blue, Color.Green, Color.Honeydew, Color.Lavender };

            for (int c = 0; c <= 10; c++)
            {
                for (int r = 0; r <= 8; r++)
                {
                    Label bricks = new Label();
                    bricks.Location = new Point(x, y);
                    bricks = brickcolor;
                    bricks.Width = 90;
                    bricks.Height = 25;
                    pnlGame.Controls.Add(bricks);
                    y += 30;
                 }
              }

1 个答案:

答案 0 :(得分:1)

for (int r = 0; r < 8; r++)
{
 Label bricks = new Label();
 bricks.Location = new Point(x, y);
 bricks.BackColor = brickcolor[r]; //or bricks.ForeColor
 bricks.Width = 90;
 bricks.Height = 25;
 pnlGame.Controls.Add(bricks);
 y += 30;
}