【发布时间】:2011-10-30 05:45:18
【问题描述】:
是否可以在新的表单实例上建立所有者?在使用主窗体和模型窗口时,我想到了这个问题,假设我创建了一个新的 Form1 实例,如下所示:
//this Instance From main window
CashDeposit cd=new CashDeposit();
cd.Show(this);
现在我将关闭它并尝试在 CashDeposit 的新 EventHandller 上创建相同的新实例,如下所示:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
this.Close();
CashDeposit cdd = new CashDeposit();
cdd.Show();
}
//this would showing without any owner but if I create the new instance on another way like below:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
this.Close();
CashDeposit cdd = new CashDeposit();
cdd.Show(this);
}
//than obviously it will going to fire the error like not creating owner on disposing object or control etc.
所以我很难从同一类中创建 CashDeposit 新实例的所有者,因为参考表单正在处理并且不知道如何从 CashDeposit 类中创建主窗口窗体和 CashDeposit 之间的新关系在相同的新实例上。
这里的主窗体是 CashDeposit 的所有者。在如上所述处理旧的(关系)表格后,我正试图在 CashDeposit 的新实例上建立所有者。
任何人都知道如何实现相同的目标?
【问题讨论】:
标签: c# winforms visual-studio