我有这个功能,它将Click event
为label list
. label list
是标签列表:
Label[] label = new Label[50]; // 50 is only a ramdom number, is not the real number of number of labels
ii
是number of labels
从label
。
orar[k]
是一个包含一些字段的列表:
static List<Orar> orar = new List<Orar>();
Orar
是列表的一个类。ii
该列表具有与(标签数)相同的字段数。
这是创建Click
事件的代码。
for (int k = 0; k < ii; k++)
{
label[k].Click += (s, e) =>
{
string materie = "", profesor = "", detali = "", zi = "", formatmaterie = "", sala = "", inputbox = "", inceputora = "", formatOra = "", saptamana = "", AMPM1 = "", p1 = "";
int cand = 1, vl1 = 0, apm = 0;
materie = orar[k].materie;
profesor = orar[k].profesor;
detali = orar[k].detali;
zi = orar[k].zi;
formatmaterie = orar[k].formatmaterie;
sala = orar[k].sala;
inceputora = orar[k].inceputora;
formatOra = orar[k].formatora.ToString();
saptamana = orar[k].saptamana;
AMPM1 = orar[k].apm;
vl1 = vl11;
cand = 1;
p1 = "Detali materie !";
apm = 0;
inputbox = Programarii.InputAddOrar.Show(p1, ref materie, ref formatOra, ref sala, ref inceputora, ref formatmaterie, ref profesor, ref zi, ref detali, ref saptamana, ref vl1, ref cand, ref apm, ref AMPM1).ToString();
};
}
问题是那行不通。我有这个错误:Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
。