单实例表格(带参数) [英] Single Instance Form (with parameters)

查看:65
本文介绍了单实例表格(带参数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的申请是这样的:

Form1 =启动表格。从数据库中读取一些数据,完成后通过参数将数据发送到form2:

Form2 f2 = new Form2(param1,param2);

并保存所有数据从参数接收一些变量

(Form2 =>有2个构造函数:一个带参数,一个没有)



表格2打开。点击链接=> Form2隐藏,表单3打开。

单击form3上的链接,我想转到隐藏的Form2实例(并设置所有变量)



我该怎么做?因为我真的需要保留Form2的两个构造函数

My application is like this:
Form1 = startup form . Reads some data from database and when finishes it send the data through parameters to form2:
Form2 f2=new Form2(param1, param2);
and saves all the data it receives from parameters to some variables
(Form2=> has 2 constructors : one with parameters and one whithout)

Form 2 open. Click on a link=> Form2 hides and form 3 opens.
Click on a link on form3 , and I want to go to the instance of Form2 that was hidden (and gots all the variables set)

How can I do this? Because I really need to keep both constructors for Form2

推荐答案

具体如何执行此操作取决于在重新显示Form2后是否希望form3可见。如果没有,那么最简单的解决方案是使用ShowDialog:

Form2

Exactly how you do this will depend on whether you want form3 visible once Form2 is re-shown. If not, then your easiest solution is to use ShowDialog:
Form2
Form3 f3 = new Form3();
Hide();
Form3.ShowDialog();
Show();



如果是,那么最好的办法就是让Form3向Form2发出一个告诉它应该再次展示自己的事件。



在表格之间处理数据并不困难。这些应该可以帮到你:



在两种表格之间传递信息,第1部分:父母对儿童 [ ^ ]



在两种表格之间转移信息,第2部分:从孩子到父母 [ ^ ]



另一种选择是在Form1中完成所有这些并让它完成工作:

在两种形式之间传递信息,第3部分:儿童到儿童 [ ^ ]


If it is, then the best thing to do is to have Form3 signal an event to Form2 that tells it it should show itself again.

Handing data between the forms isn''t difficult. These should help you:

Transferring information between two forms, Part 1: Parent to Child[^]

Transferring information between two forms, Part 2: Child to Parent[^]

The other option is to do all this in Form1 and have it do the work:
Transferring information between two forms, Part 3: Child to Child[^]


public部分课程表格2:表格

{

公共表格2()

{



}

public Form2(字符串par1,字符串par2)

{



}





public void LinkBut​​ton_Click(object sender,EventArgs e)

{

Form3 objFrm3 = new Form3(this);

objFrm3.Show();

}

}



公共部分类Form3:表格

{

Form2 objFrm2 = null;

public Form3(Form2 obj)

{

objFrm2 = obj;

}



public void LinkBut​​ton_Click(object sender,EventArgs e )

{

//现在你将获得form2中的所有变量

objFrm2.Show();

}

}
public partial class Form2 : Form
{
public Form2()
{

}
public Form2(string par1,string par2)
{

}


public void LinkButton_Click(object sender, EventArgs e)
{
Form3 objFrm3 = new Form3(this);
objFrm3.Show();
}
}

public partial class Form3 : Form
{
Form2 objFrm2 = null;
public Form3(Form2 obj)
{
objFrm2 = obj;
}

public void LinkButton_Click(object sender, EventArgs e)
{
// you will now get all your varialbes in form2
objFrm2.Show();
}
}


这篇关于单实例表格(带参数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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