lundi 9 novembre 2020

Set property of control using reflection

How to get/set property of control (in this case Button)?

I tried on this way:

Type t = Type.GetType("System.Windows.Forms.Button");
PropertyInfo prop = t.GetType().GetProperty("Enabled");
if (null != prop && prop.CanWrite && prop.Name.Equals("button1"))
{
    prop.SetValue(t, "False", null);
}

but t is null. What is wrong here?





Aucun commentaire:

Enregistrer un commentaire