奥菲😾 天恨彻
就喜欢吃饭睡觉晚电脑。。。哈哈哈
关注数: 17 粉丝数: 77 发帖数: 4,783 关注贴吧数: 48
新人求助,关于遍历的问题 public partial class Form1 : Form { Label[,] lbls = new Label[4, 4]; //保存4x4标签的二维数组 string[] indexes = new string[] { "0,0", "0,1", "0,2", "0,3", "1,3", "2,3", "3,3", "3,2", "3,1", "3,0", "2,0", "1,0" };//用于确定外围标签遍历顺序的数组 int index = 0; //控制移动变色的标签位置 string[] files = { "葡萄.png", "苹果.png", "西瓜.png", "橘子.png","星星.png","幸运7.png","空.png","铃铛.png" ,"花费.png"}; string[,] files1 = { { "空.png", "橘子.png", "葡萄.png", "空.png" }, { "星星.png", "苹果.png", "空.png", "幸运7.png" }, { "铃铛.png", "铃铛.png", "葡萄.png", "苹果.png" }, { "空.png", "花费.png", "西瓜.png", "空.png" } }; int[,] score = { { 0, 30, 10, 0 }, { 60, 20, 0, 50 }, { 80, 80, 10, 20 }, { 0, 100, 40, 0 } }; public Form1() { InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { foreach (Control lbl in this.panel1.Controls) //把窗体上所有的标签色全部变为红色 { button1.BackColor = Color.White; lbl.BackColor = Color.Red; } string[] array = indexes[index].Split(','); int x = Convert.ToInt32(array[0]); int y = Convert.ToInt32(array[1]); lbls[x, y].BackColor = Color.Blue; index++; if (index == 12) { index = 0; } } private void Form1_Load(object sender, EventArgs e) { Random rnd = new Random(); for (int i = 0; i <= lbls.GetUpperBound(0); i++) { for (int j = 0; j <= lbls.GetUpperBound(1); j++) { if (i == 0 || j == 0 || i == 3 || j == 3) //当处于二维数组中最外圈时 { Label lbl = new Label(); //动态创建标签对象 lbl.BackColor = Color.Red; int index = rnd.Next(0, 4); lbl.Image = Image.FromFile(files1[i,j]); lbls[i, j] = lbl; //把标签加入二维数组中相应的位置 lbl.AutoSize = false; lbl.Size = new System.Drawing.Size(80, 80); lbl.Text = ""; lbl.BorderStyle = BorderStyle.Fixed3D; this.panel1.Controls.Add(lbl); //同时把标签加入窗体中 lbls[i, j].Tag = score[i, j]; lbl.Location = new Point(5 + i * 80, 5 + j * 80); //控制标签在窗体上显示的位置 } } } } private void button1_Click(object sender, EventArgs e) { timer1.Enabled = !timer1.Enabled; //用按钮控制timer的运行和停止 foreach (Control lbl in this.Controls) / /这里问题来了,这里要求是在timer停止 { / /判断哪个lbl为蓝色,并获取蓝色lbl的分数 this.Controls.Add(lbl); / / 这部怎么做遍历原来的lbl的 int num = int.Parse(lbl.Tag.ToString()); } }
首页 1 2 下一页