It is necessary to create several (unknown how many) labels and to determine the pressing method for each. All this should happen cyclically.
public Form1() { InitializeComponent(); flag1 = true; ReadXMLDocument("new.xml", "Π£ΠΏΡΠ°Π²Π»Π΅Π½ΠΈΠ΅ ΠΏΡΠΎΠ΅ΠΊΡΠ°ΠΌΠΈ"); arrLabel[] la = new arrLabel[arrLength]; int length, floor, column, row; floor = length = 20; column = row = 0; tableLayoutPanel1.AutoScroll = true; tableLayoutPanel1.AutoSize = true; for (int i = 0; i < arrLength; ++i) { la[i] = new arrLabel(result[i], countRes[i]); la[i].lbl.Size = new Size(160, 20); la[i].lbl.Location = new Point(floor, length); la[i].lbl.AutoSize = true; la[i].lbl.Click() = (sender, args) => la[i].action(); tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; tableLayoutPanel1.Controls.Add(la[i].lbl, column, row); if (floor < 400) { floor += 150; } else length += 20; if (column == 4) { row++; column = 0; } else column++; Console.WriteLine(column + " " + row); }
var label = new Label(); label.Click += (s,e) => MessageBox.Show("ΠΡΠ°Π»Ρ!");
- Veikedo