形式上的反思 [英] Reflection in Form

查看:69
本文介绍了形式上的反思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在表单中使用反射来获取在运行时创建的控件的属性,文本,名称等?

How can i use reflection in forms to get attributes, text, name etc of controls i created at runtime ?

推荐答案

尝试使用Controls集合.您可以使用ForEach(Control C in this .controls)

然后,您可以测试控件的类型并获取其名称等.
Try using the Controls collection. You can use ForEach(Control C in this .controls)

Then you can test the controls types and get their names etc.


测试控件的类型
测试控件的名称
根据控件的类型,然后获取您想要的内容

如果C.typeof(textbox)
内容= C.Text
Test the type of the control
Test the name of the control
Based on the type of control then get the content you are after

If C.typeof(textbox)
content = C.Text


这篇关于形式上的反思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆