Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.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# MDI容器窗体未打开_C#_Winforms_C# 2.0_Mdi_Mdichild - Fatal编程技术网

C# MDI容器窗体未打开

C# MDI容器窗体未打开,c#,winforms,c#-2.0,mdi,mdichild,C#,Winforms,C# 2.0,Mdi,Mdichild,我有两个表单,分别是mdfi和form1。我想通过form1中的代码制作mdfi表单aMdiContainer。我尝试了以下操作,但运行时程序关闭: private void Form1_Deactivate(object sender, EventArgs e) { this.TopMost = false; Mdfi newMDIChild = new Mdfi(); newMDIChild.IsMdiContainer = true; this.MdiPar

我有两个表单,分别是
mdfi
form1
。我想通过
form1
中的代码制作
mdfi
表单a
MdiContainer
。我尝试了以下操作,但运行时程序关闭:

private void Form1_Deactivate(object sender, EventArgs e)
{
    this.TopMost = false;
    Mdfi newMDIChild = new Mdfi();
    newMDIChild.IsMdiContainer = true;
    this.MdiParent = newMDIChild;
    newMDIChild.Show();
}

将应用程序的主窗口更改为子窗口有许多副作用。Winforms由于MdiParent分配而被迫销毁窗口。这足以让Main()方法中的Application.Run()调用完成,这就是应用程序的结束。你必须改变这一点:

    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        var main = new Form1();
        main.Show();
        Application.Run();
    }
您必须确保现在在MDI父级关闭时终止:

    private void Form1_Deactivate(object sender, EventArgs e) {
        this.TopMost = false;
        var newMdiParent = new mdfi();
        newMdiParent.IsMdiContainer = true;
        this.MdiParent = newMdiParent;
        newMdiParent.FormClosed += (s, ea) => Application.Exit();
        newMdiParent.Show();
        this.Deactivate -= Form1_Deactivate;
    }

    private void Form1_FormClosed(object sender, FormClosedEventArgs e) {
        if (this.MdiParent == null) Application.Exit();
    }

为什么在Deactivate事件()期间尝试添加表单!我正在使图片查看器看起来像Google picasa,因此,当用户在屏幕上单击任何地方时,它会生成一个mdi表单,并且图像适合该表单。mdi表单位于父表单中。我不确定这是否是你想要的。当调用此代码时,您是否按[X]按钮关闭
form1
?@JeffBridgman当我的form1停用时,我想将我的“mdfi”表单设置为mdi父级。