开发者

how to set text property assigned to the control created dynamically usiong reflection?-C#

开发者 https://www.devze.com 2023-01-17 12:50 出处:网络
how to set text propertyassigned to the control created dynamically usiong reflection? Type type = Type.GetType(strFullName);

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";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消