private void makubex()
{
lb = new ListBox();
for (int i = 0; i < grid.ColumnDefinitions.Count; i++)
{
for (int j = 0; j < grid.RowDefinitions.Count; j++)
{
Rectangle rect = new Rectangle();
SolidColorBrush scb = new SolidColorBrush(GetRandomColor());
lb.Items.Add(scb.ToString());
grid.Children.Add(rect);
rect.SetValue(Grid.RowProperty, i);
rect.SetValue(Grid.ColumnProperty, j);
rect.Fill = scb;
}
}
ShowPop();
}
Random random = new Random();
public Color GetRandomColor()
{
return Color.FromRgb((byte)random.Next(0, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255));
}
Random 不能放到 GetRandomColor 方法里 这样生成不出五彩的格子