在Winform C#中获取Form作为参数 [英] Get Form as parameter in winform c#

查看:431
本文介绍了在Winform C#中获取Form作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我的申请表中有一些表格.我想在流程中打开每个表单
通过获取参数.当parameter等于表单名称时,将显示该表单.
在以下几行中,"_ my_Form"是一个参数,它包含我的项目中存在的表单的名称.
但是此过程无法正常工作.

表格f;
f = null;
f.Name = _my_Form;
f.ShowDialog();

我该怎么办?

非常感谢

Hi I have some forms in my application. I wants open each of forms in a process
By get parameter . when parameter be equal the name of a form, that form would be shown.
In following lines, "_my_Form" is a parameter contains name of a forms which exist in my project.
But this process not work well.

Form f ;
f = null;
f.Name = _my_Form;
f.ShowDialog();

How can I do it?

Thanks very much

推荐答案

您可以通过 ^ ],但这不是一个好主意,通常表示您的设计中有很多错误,除非您经验丰富并编写了一些非常精美的代码.

出于这个原因,我只给您留下链接,而不是给您代码-如果您知道自己在做什么以使用它,那是一回事:但是这样做无疑会更好.一种不同的方式!
You can do it using Reflection, via the Activator.GetInstance method[^], but...it''s not a good idea, and generally indicates that something is very wrong in your design, unless you are very experienced and doing some very fancy code.

For that reason, I''ll just leave you with the link rather than give you code - if you know what you are doing enough to use it, then that''s one thing: but you would almost certainly be better off doing this a different way!


这篇关于在Winform C#中获取Form作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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