我想随机选择按钮的颜色。当我这样做的时候,它会起作用Change_color(But0_0)。但是我想使用function使它自动工作for。但这不起作用(停止程序)。private void But0_0_Click(object sender, RoutedEventArgs e){ for (int i = 1; i <= 20; i++) { var ele = MainGrid.FindName("But0_" + i); Button button = ele as Button; Change_color(button); } Change_color(But0_0);}private void Change_color(Button name){ Random rand = new Random(); Color[] colors = new Color[] { Colors.Red, Colors.Blue, Colors.Green, }; name.Background= new SolidColorBrush(colors[rand.Next(0, 3)]);}
1 回答
- 1 回答
- 0 关注
- 186 浏览
添加回答
举报
0/150
提交
取消