通过变量打开表格 [英] form open by variable

查看:95
本文介绍了通过变量打开表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在字符串varible中有表单名.我想在C#中按字符串形成
(将字符串转换为C#中的Form)

问候
S.Murugesan

i have formname in string varible .i want to form by string in C#
(convert string to Form in C#)

Regards
S.Murugesan

推荐答案

<br />
string formName = "MyFormName";<br />
Form myForm = System.Windows.Forms.Application.OpenForms[formName];<br />


S.murugesan写道:
S.murugesan wrote:

我在字符串varible中具有formname

i have formname in string varible



如果这是表单类的名称,则可以使用类似以下内容的内容:



If this is a name of your form class then you could use something like:

// If the class name is stored in "formClass" string variable
Type formType = Type.GetType(formClass);
Form myForm = (Form)Activator.CreateInstance(formType);



如果未创建表单,则可以使用这种方法.
如果您的表单已经创建,请参阅Kemo72000的帖子.

问候



This approach could be used if your form is not created.
If your form is already created then see the post from Kemo72000.

Regards


S.murugesan写道:
S.murugesan wrote:

(在C#中将字符串转换为Form)

(convert string to Form in C#)



:omg::omg​​:

你在说什么?

您是否要以以下形式显示字符串内容?

如果是这样,只需创建一个标签并通过一些属性将其公开.



:omg: :omg:

What are you talking about ?

Do you mean to show the string content in the form ?

If so, just create a label and expose it through some property.

public string MyLabel
{
 get{ return this.Label1.Text;}
 set { this.Label1.Text = value; }
}


现在从您的表格中,


Now from your form,

MyForm f = new MyForm();
f.MyLabel = mystring;



希望这就是您想要的.
:thumbsup:



I hope this is what you wanted.
:thumbsup:


这篇关于通过变量打开表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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