Software Development Network>> Visual C#>> How can I set a property value by name in runtime?
Here's a snippet that shows how to set the width of a form during runtime.
Form form = new Form(); form.Width = 100;
Type formType = form.GetType(); System.Reflection.PropertyInfo propInfo = formType.GetProperty("Width"); if (propInfo != null) { propInfo.SetValue(form, 200, new object[] { }); } Debug.Assert(form.Width == 200);
How can I set a property value by name in runtime?
Scott Hathaway
Lck
Here's a snippet that shows how to set the width of a form during runtime.
Form form = new Form();
form.Width = 100;
Type formType = form.GetType();
System.Reflection.PropertyInfo propInfo = formType.GetProperty("Width");
if (propInfo != null)
{
propInfo.SetValue(form, 200, new object[] { });
}
Debug.Assert(form.Width == 200);