У меня есть массив кнопок(2*16) и массив лейблов(5*5). Нельзя ли как нибудь для них создать общую функцию,чтоб уменьшить код?
| Код | for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { Royals[i, j] = new Label(); Royals[i, j].Location = new Point(x, y); Royals[i, j].Size = xy; Royals[i, j].Text = ""; Royals[i, j].AutoSize = false; Royals[i, j].BorderStyle = BorderStyle.FixedSingle; Royals[i, j].BackColor = Color.Yellow; Royals[i, j].Font = new Font("Arial", 16F); Royals[i, j].TextAlign = ContentAlignment.MiddleCenter; Royals[i, j].Tag = new Point(i,j); Royals[i, j].Click += new System.EventHandler(Label_click); Controls.Add(Royals[i, j]); x += 30; IsEmpty[i, j] = true; SelectedLabels[i, j] = false; } x =200; y += 30; }
for (int i = 0; i < 2; i++) { for (int j = 0; j < 16; j++) { SybButtons[i, j] = new Button(); SybButtons[i, j].Location = new Point(x,y); SybButtons[i, j].Size = xy; SybButtons[i, j].Text = symbols[i, j]; SybButtons[i, j].BackColor = Color.Aqua; SybButtons[i, j].Font = new Font("Arial",16F); SybButtons[i, j].TextAlign = ContentAlignment.MiddleCenter; SybButtons[i,j].Tag=new Point(i,j); SybButtons[i, j].Click +=new System.EventHandler(Button_Click); Controls.Add(SybButtons[i, j]); x += 30; } x = 33; y += 30; }
|
|