Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当我打开一个子窗体时,如何禁用主窗体_C#_Winforms_Monogame - Fatal编程技术网

C# 当我打开一个子窗体时,如何禁用主窗体

C# 当我打开一个子窗体时,如何禁用主窗体,c#,winforms,monogame,C#,Winforms,Monogame,我一直在到处寻找,我还没有找到当子窗体打开时禁用主窗体的代码,我可能只是用词不对。就像当你打开一个文件时,如果你尝试点击应用程序,打开的文件会闪烁并发出声音 当我处于非主窗体的第二个窗体时,如何使应用程序禁用 编辑:这就是它的位置,因为每个人都在问 private void newToolStripMenuItem_Click(object sender, EventArgs e) { New_File newFile = new New_File();

我一直在到处寻找,我还没有找到当子窗体打开时禁用主窗体的代码,我可能只是用词不对。就像当你打开一个文件时,如果你尝试点击应用程序,打开的文件会闪烁并发出声音

当我处于非主窗体的第二个窗体时,如何使应用程序禁用

编辑:这就是它的位置,因为每个人都在问

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
    {
        New_File newFile = new New_File();
        if (newFile.ShowDialog() == DialogResult.OK)
        {

        }
    }
编辑2:打开文件需要16秒,如下所示:

既然你抢走了我所有的代表,我就得发个链接


我还是不明白为什么当我不知道ShowDialog是什么的时候,你们仍然对我投反对票。

当你们打开“子表单”使用

form1.ShowDialog();

这将显示新表单,在该表单关闭之前,您将无法访问其外部的任何内容。

您需要使主表单拥有子表单,并显示子表单

对于WinForms:将所有者传递给。 对于WPF:设置then调用。 Winforms:

显示一个对话框。没什么可说的了

一个小技巧:


这很简单,只有点击Form2中的按钮,主窗体才能访问。

如果您想在主窗体可见但处于禁用模式时显示子窗体,只需按照以下代码操作:

subForm.ShowDialog(); //Shows both main and sub form , but the main form is not accessible .
但如果要隐藏主窗体,请执行以下示例:

this.Hide(); //Hides the main form.
subForm.ShowDialog(); //Shows the sub form.
this.Show(); //Shows the main form again after closing the sub form.

你没有遇到ShowDialog?我在C语言方面的知识有限,试图用我的技能创造一些先进的东西。所以我不知道。我发现ShowDialog只适用于OpenFileDialog和SaveFileDialog。这是同样的事情。当你打开一个SaveFileDialog窗口时,除非它被关闭,否则你不能访问该窗口之外的任何东西。这与有限的知识无关。只要把你的问题标题输入谷歌,它就会给你答案。你真的到处找过了吗?还是让别人帮你找比较容易?试试newFile.ShowDialogthis。@downvoter:想详细说明一下吗?
subForm.ShowDialog(); //Shows both main and sub form , but the main form is not accessible .
this.Hide(); //Hides the main form.
subForm.ShowDialog(); //Shows the sub form.
this.Show(); //Shows the main form again after closing the sub form.