在c#window应用程序中将字符串转换为表单对象 [英] Convert string to form object in c# window application

查看:84
本文介绍了在c#window应用程序中将字符串转换为表单对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在开发窗口应用程序C#.net 2010 ...



我的问题很简单,我从数据库中获取表格名称...



现在我要打开使用来自数据库的名称/字符串的表单...

如何在c#窗口应用程序中将字符串转换为表单对象



请回复我.........

Hi,
I''m developing window application C#.net 2010...

My question is simple, i''m getting form name from database...

now i want to open the form using name/string coming from database...
how to convert string to form object in c# window application

please reply me.........

推荐答案

如果您的意思是在数据库中存储thr表单类的名称,如:

If you mean that you are storing the name of thr form class in the database, as in:
MyForm form = new MyForm();

并存储字符串MyFormin你的数据库,你可以用反射来做:

And you store the string "MyForm" in your db, you can do it with reflection:

Type t = Type.GetType("MyNamespace." + "frmMyFormClass");
Form c = Activator.CreateInstance(t) as Form;
c.Show();


你可以使用

1-string name = Convert.ToString(objName);

2-string name = objName.Tostring();

3-string defaultName;

string.TryParse(objName,out defaultName);



我认为这些方法可以将对象转换为字符串。
You can use
1-string name = Convert.ToString(objName);
2-string name = objName.Tostring();
3-string defaultName;
string.TryParse(objName,out defaultName);

I think these way u can convert a object to string.


这篇关于在c#window应用程序中将字符串转换为表单对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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