Control c = null; switch(controlType.ToUpper()) { case "BUTTON": c = new Button(); break; case "TEXTBOX": c = new TextBox(); break; case "LABEL": c = new Label(); break; default: throw new Exception("Unrecognized control type: " + controlType); } c.Text = controlText; ...
Control c = null;
switch(controlType.ToUpper())
{
case "BUTTON": c = new Button(); break;
case "TEXTBOX": c = new TextBox(); break;
case "LABEL": c = new Label(); break;
default: throw new Exception("Unrecognized control type: " + controlType);
}
c.Text = controlText;
...
感谢了,昨天也想了这个问题,反射的东西没接触过,看资料感觉很复杂,变通的方式还是gomoku说的这种较为简单,虽然没有真正实现完全动态对我的这个功能已经足够了。。