Skip to main content
 首页 » 编程设计

C# "Form that is already visible cannot be displayed as a modal dialog box. Set the form' 的可见属性在调用 showDialog 之前设置为 false。”

2024年02月05日17qq号

这是我在表单中的代码。这个函数应该打开另一个我作为对话框创建的表单,但我一直收到错误:

Form that is already visible cannot be displayed as a modal dialog box. Set the form's visible property to false before calling showDialog.

我查看了所有表单属性,但无法在任何地方找到它。我错过了什么?使用 Visual Studio 2015 和带有 .net 4 的 winforms 应用程序

    private void disconnect_Click(object sender, EventArgs e) 
    { 
        ShowDialog(new ManagerWarning()); 
    } 

请您参考如下方法:

您实际上是在尝试调用当前 View 的 ShowDialog 方法,将 new ManagerWarning() 作为参数(实际上,尝试将当前 View 作为模态,以新形式作为父形式)。

创建窗体 ManagerWarning 的实例并尝试以这种方式运行

private void disconnect_Click(object sender, EventArgs e) 
    { 
        ManagerWarning m = new ManagerWarning(); 
        m.ShowDialog(); 
    }