how to set text property assigned to the control created dynamically usiong reflection?
Type type = Type.GetType(strFullName);
object instance = Activator.CreateInstance(type);
ctrlTemp = (Control)instance;
ctrlTemp.ID = "Hell开发者_运维技巧o";
ctrlTemp.Text???
Panel1.Controls.Add(ctrlTemp);
PropertyInfo.SetValue Method : Sets the value of the property with optional index values for index properties.
PropertyInfo piInstance =
typeof(Example).GetProperty("InstanceProperty");
piInstance.SetValue(exam, 37, null);
if (ctrlTemp.GetType() == typeof(TextBox))
{
TextBox textbox = (TextBox)ctrlTemp;
ctrlTemp.Text = "Your text";
}
精彩评论