简体   繁体   English

已经可见的窗体不能显示为模式对话框

[英]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();

See this answer 看到这个答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#“已经可见的表单无法显示为模式对话框。 在调用showDialog之前,将表单的visible属性设置为false。” - C# “Form that is already visible cannot be displayed as a modal dialog box. Set the form's visible property to false before calling showDialog.” 不是顶级窗体的窗体不能显示为模式对话框。 在调用showDialog之前,从任何父表单中删除该表单 - Form that is not a top-level form cannot be displayed as a modal dialog box. Remove the form from any parent form before calling showDialog 在辅助监视器上显示时,模态形式会失去控制框功能 - Modal form loses control box functionality when displayed on a secondary monitor 模态对话框 - Modal Dialog Box 当应用程序不在UserInteractive模式下运行时,显示模式对话框或窗体 - Showing a modal dialog box or form when the application is not running in UserInteractive mode 将回调发送到对话框模式 - Sending callbacks to dialog box modal 如何使ContextMenu在模式对话框后可见 - How to keep a ContextMenu visible behind a modal dialog 表单不能动态显示 - Form cannot be displayed dynamically 当应用程序不在UserInteractive模式下运行时,显示模式对话框或窗体不是prod服务器中的有效操作错误 - Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation error in prod server 在IIS中承载WCF服务会导致错误“在应用程序中显示模式对话框或窗体……” - Hosting WCF service in IIS cause an error “Showing a modal dialog box or form when the application…”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM