通过名称创建表单(System.Windows.Forms.Form的字符串) [英] Create form by Name (String to System.Windows.Forms.Form)

查看:58
本文介绍了通过名称创建表单(System.Windows.Forms.Form的字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

我希望你能帮助我.我正在开发一个新项目,该项目有多个屏幕.好吧,我想通过她的名字创建一个屏幕,这个名字与屏幕的类名相同.

示例:

我创建一个新屏幕,并将她的名字命名为formCadastro.现在,以我的基本形式,我将转到一个函数字符串值"formCadastro".功能并打开具有相同名称的屏幕.

是否有可能?我尝试使用System.Windows.Forms.Form类进行一些工作,但我无法...谢谢您的帮助.

全部成功

Friends,

I hope you can help me. I am developing a new project and this project I have several screens. Well, I would like to create a screen through her name and that name is the same class name of the screen.

Example:

I create a new screen, and put her name as formCadastro. Now, in my base form, I would go to a function the string value "formCadastro" function and open the screen with the same name.

Is it possible? I tried to work a little with the System.Windows.Forms.Form class but I could not ... Thank you for your help.

Success for All

推荐答案

可能,

System.Reflection是您需要研究的程序集.通过反射,您可以实例化对象,填充属性并从其描述/名称调用methdod.

在此处查看有关类似问题的信息
http://social.msdn.microsoft.com /Forums/zh-CN/netfxbcl/thread/4d915685-a728-42d9-99e0-02e16dc159d1/ [
It is possible,

System.Reflection is the assembly you need to look into. With reflection you can instantiate objects, populate properties and call methdod from their descriptions/ names.

See here for a post regarding a similar problem here
http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/4d915685-a728-42d9-99e0-02e16dc159d1/[^]


It might be worth thinking about why you need to do this first, however, as it might be a sign of incorrect design.

Doing things by reflection is slightly slower (in newer versions of the framework, older versions are *much* slower). Also the code is far more difficult to read.


这篇关于通过名称创建表单(System.Windows.Forms.Form的字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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