[英]form that is already visible cannot be displayed as a modal dialog box
In my program I open every form with the help of ShowDialog
and close previous one with the help of: 在我的程序中,借助
ShowDialog
打开每个表单,并借助以下命令关闭上一个表单:
this.Hide();
...some code...
this.Close();
But when I want to open Form for a second time, I get the error that is in the title. 但是,当我想第二次打开Form时,出现标题中的错误。 What can it be?
会是什么 Maybe it's because I use Singleton patter for that form that I want to open for a second time.
也许是因为我想再次打开该表格的单例模式。
Instead of continually showing forms using ShowDialog
you can just create new instances of each form as you need them. 不必使用
ShowDialog
连续显示表单,而是可以根据需要创建每个表单的新实例。 For example 例如
using(Form frm = new Form1)
{
DialogResult dr = frm.ShowDialog(this)
if(dr == DialogResult.Cancel)
{
...
}
}
or 要么
Form frm = new Form1();
DialogResult dr = frm.ShowDialog(this);
if(dr == DialogResult.Cancel)
{
...
}
frm.Dispose();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.