Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.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父窗体中的MDI父窗体_C# - Fatal编程技术网

C# 另一个MDI父窗体中的MDI父窗体

C# 另一个MDI父窗体中的MDI父窗体,c#,C#,我使用以下方法成功打开MDI父窗体中的MDI父窗体: 我制作了两个桌面应用程序(即App1和App2),启动时使用MDI父窗体。 在App1中,我在MDI父级上添加了一个面板,我们将在其中打开另一个应用程序,即App2。 现在我在App1中添加了这段代码 及 现在,在按钮点击事件中,使用以下代码。(App1) 这里,Application.StartupPath+@“\App2.exe”是我构建的进程或exe文件(您知道,构建解决方案)。首先,当我使用断点进行调试时,代码工作正常,但当我尝试运行

我使用以下方法成功打开MDI父窗体中的MDI父窗体: 我制作了两个桌面应用程序(即App1和App2),启动时使用MDI父窗体。 在App1中,我在MDI父级上添加了一个面板,我们将在其中打开另一个应用程序,即App2。 现在我在App1中添加了这段代码

现在,在按钮点击事件中,使用以下代码。(App1)

这里,Application.StartupPath+@“\App2.exe”是我构建的进程或exe文件(您知道,构建解决方案)。首先,当我使用断点进行调试时,代码工作正常,但当我尝试运行它时,App2将作为不同的进程打开,而不是在App1中打开。其次,我无法打开我在App2中添加的表单,该表单作为MDI子表单(App2)打开


这是我在MDI窗体中打开子窗体的方式。

SetParent()支持这一点,因为这在Windows版本3中是可能的。还没有进程和线程的Windows版本。这仍然会有一个好的结局的几率与你的程序表现得像Windows3.x程序成反比。20年后,这些几率变得很低。否则,完全缺乏错误检查也使得诊断问题变得不可能。需要使用SetLastError=true并在winapi函数返回失败代码时引发Win32Exception。那么我应该做什么更改(bcoz我无法完全理解您的注释)?第二,我尝试用同样的方法打开notepad.exe。它成功了。@hans Passnat:我把代码改成了,我可以得到我想要的。但我仍然很想知道你们的评论(只是为了了解情况)。还有一件事我仍然无法在MDIParent2中打开表单,它现在在面板(app1)中打开。
// Create a new process
Process proc;

// Start the process
proc = Process.Start(Application.StartupPath + @"\App2.exe");
proc.WaitForInputIdle();

// Add this by using using System.Threading;
Thread.Sleep(500);

// Set the panel control as the application's parent
SetParent(proc.MainWindowHandle, this.panel1.Handle);
[DllImport("user32.dll")]
    static extern IntPtr SetParent(IntPtr hwndChild, IntPtr hwndNewParent);
    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
    static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, Int32 wParam, Int32 lParam);
    // Create a new process
        Process proc;

        // Start the process
        proc = Process.Start(Application.StartupPath + @"\App2.exe");
        ////proc = Process.Start("notepad.exe");
        proc.WaitForInputIdle();

        // Set the panel control as the application's parent
        SetParent(proc.MainWindowHandle, this.panel1.Handle);

        // Maximize application
        SendMessage(proc.MainWindowHandle, 274, 61488, 0);
        MessageBox.Show(Application.OpenForms[0].ToString());
  Form1 frm = new Form1();
        frm.MdiParent = Application.OpenForms[0];
        frm.Show();
// Create a new process
Process proc;

// Start the process
proc = Process.Start(Application.StartupPath + @"\App2.exe");
proc.WaitForInputIdle();

// Add this by using using System.Threading;
Thread.Sleep(500);

// Set the panel control as the application's parent
SetParent(proc.MainWindowHandle, this.panel1.Handle);