有了这个代码,我可以在运行时创建标签:
ArrayList CustomLabel = new ArrayList();
foreach (string ValutaCustomScelta in Properties.Settings.Default.ValuteCustom)
{
CustomLabel.Add(new Label());
(CustomLabel[CustomLabel.Count - 1] as Label).Location = new System.Drawing.Point(317, 119 + CustomLabel.Count*26);
(CustomLabel[CustomLabel.Count - 1] as Label).Parent = tabPage2;
(CustomLabel[CustomLabel.Count - 1] as Label).Name = "label" + ValutaCustomScelta;
(CustomLabel[CustomLabel.Count - 1] as Label).Text = ValutaCustomScelta;
(CustomLabel[CustomLabel.Count - 1] as Label).Size = new System.Drawing.Size(77, 21);
Controls.Add(CustomLabel[CustomLabel.Count - 1] as Control);
}
我需要创建tabPage2标签,但该行不行:
(CustomLabel[CustomLabel.Count - 1] as Label).Parent = tabPage2;
这是正确的指令,以在运行时创建tabPage2标签? (IM使用Visual Studio 2010,窗口形式)