使用此代码,我可以在运行时创建标签:
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 上创建标签的正确指令?(我使用 Visual Studio 2010,Windows 窗体)