通过变量打开表格 [英] form open by variable
问题描述
我在字符串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 />
我在字符串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
(在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屋!