以另一种形式访问许多表单 [英] Access to many forms in another form
问题描述
我最好的朋友。
我有一个表格,可以通过20个其他表格调用它们不相同。我可以访问20个表格中的每个表格从它调用时开始。
I have a form that calling by 20 other forms that they are not the same.how can i Access to each of the 20 Forms in that from when it calls.
我的解决方案是使用具有不同输入的构造函数,这意味着有20个构造函数!
My solution is to use constructors with different inputs ,that means have 20 constructors !
form1 frm1=null;
public myFrom(form1 f)
{
InitializeComponent();
frm1=new form1();
frm1=f;
}
form2 frm2=null;
public myFrom(form2 f)
{
InitializeComponent();
frm2=new form2();
frm2=f;
}
依旧...
我的另一个解决方案是为每个人提供一个新表格!
my other solution is Having a new form for each one !
解决这个问题的最佳方法是什么?!
What is the best way to solve this problem ?!
推荐答案
嗨Arash,
Hi Arash,
我不确定 做什么你想要做的,如果你想访问myForm中的另一个表单,你一次只能调用一个构造函数,实际上你不需要创建很多构造函数,你可以创建一个你想要访问的表单实例,只需
喜欢:
I'm not sure what do you want to do, if you want to access another forms in your myForm, you can only call a constructor at a time, actually you needn't create many constructors, you can create a instance of the form what you want to access, just like:
myForm.cs:
myForm.cs:
Form1 f1 = null;
Form2 f2 = null;
private void button1_Click(object sender, EventArgs e)
{
f1 = new Form1();
//f1.something
}
private void button2_Click(object sender, EventArgs e)
{
f2 = new Form2();
//f2.something
}
如果我误解了你的意思,你想要使用构造函数做某事,但你不想创建这么多的构造函数,你可以使用List<>实现它:
If I misunderstand what you mean, you want to use the constructor to do something, but you do not want to create so many constructors, you can use List<> to achieve it:
public MyForm(List<Form> Forms)
{
InitializeComponent();
f1 = new Form1();
Forms.Add(f1);
f2 = new Form2();
Forms.Add(f2);
}
List<Form> Forms = new List<Form>();
问候,
Stanly
这篇关于以另一种形式访问许多表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!