【发布时间】:2017-12-02 14:26:03
【问题描述】:
我有一个根据用户选择更改标题的表单。然后我想为控件创建一个属性,单选按钮或复选框。它们具有相同的属性,但我无法很好地实现。
private void DeleteEdit()
{
Control[] EmployeesControl; //I think this is the problem, but i cant figure it out.
if (Form_AddEmployee.Text.Contains("Edit"))
{
EmployeesControl = new RadioButton[numberOfEmployees];
}
else if (Form_AddEmployee.Text.Contains("Delete"))
{
EmployeesControl = new CheckBox[numberOfEmployees];
}
for (int i = 0; i < EmployeesControl.Count(); i++)
{
EmployeesControl[i] = new EmployeesControl();
InitializeControls(EmployeesControl[i]);
EmployeesControl[i].Visible = true;
panelEmployee.Controls.Add(EmployeesControl[i]);
EmployeesControl[i].Text = stringTemp;
EmployeesControl[i].Location = new Point(100, 100 * (i+1));
EmployeesControl[i].Font = MyFont;
EmployeesControl[i].CheckedChanged += EmployeesDeleteEditEmployees_CheckedChanged;
}
}
如果某个控件是单选按钮或复选框,我如何创建变量。
【问题讨论】:
-
提示:
isortypeof. -
尝试用一个代码块来做这件事并没有什么收获。但是...摆脱数组,将其设为
For (int i = 0; i < numberOfEmployees; i++),然后执行您的 If 块。