我知道下面的代码会造成溢出,因为它被第二次调用。 这就是解释, 假设我有Form1、Form2、Form3
和表单1中
Form NewForm2 = new Form2;
和表单3
Form NewForm3 = new Form2;
当我显示Form2当然是它的堆栈溢出时,因为它在Form1和Form3上被第二次调用,
好的,那么我的问题是,有没有一种方法可以将Form2从多个称为它的表单连接起来?有什么推荐人吗?
我的问题是,有没有一种方法可以将多个表单连接起来? 是,只需在您的表单上应用Singleton Pattern
public partial class Form2 : Form
{
private static Form2 inst;
public static Form2 GetForm
{
get
{
if (inst == null || inst.IsDisposed)
inst = new Form2();
return inst;
}
}
}
显示您的表单
Form2.GetForm.Show();