简体   繁体   English

其他MDI父表单中的MDI父

[英]MDI parent within another MDI parent form

I am succeeded in opening MDI parent form within MDi parent form by using following method: I made two desktop applications(ie App1 and App2) having MDI parent forms as startup. 通过使用以下方法,我成功在MDi父窗体中打开了MDI父窗体:我制作了两个具有MDI父窗体作为启动的桌面应用程序(即App1和App2)。 In App1, I have added a panel on MDI parent in which we are going to open the other app ie App2. 在App1中,我添加了一个有关MDI父级的面板,我们将在其中打开另一个应用程序,即App2。 Now I added this code in App1. 现在,我在App1中添加了此代码。

 using System.Diagnostics; using System.Runtime.InteropServices; 

and

 [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);

Now in button click event the following code is used.(App1) 现在在按钮单击事件中使用以下代码。(App1)

    // 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());

Here,Application.StartupPath + @"\\App2.exe" is the process or EXE file which I built (Build solution, you know). 在这里,Application.StartupPath + @“ \\ App2.exe”是我生成的进程或EXE文件(您知道生成解决方案)。 Firstly,The code works fine when I debug with breakpoint but when I try to run it, the App2 opens as a different process but not in App1. 首先,当我使用断点进行调试时,代码可以正常工作,但是当我尝试运行它时,App2将作为一个不同的进程打开,但不会在App1中打开。 Secondly, I cannot open form which i have added in App2 which is opened as MDI child form (app2). 其次,我无法打开在App2中添加的窗体,该窗体是作为MDI子窗体(app2)打开的。

  Form1 frm = new Form1();
        frm.MdiParent = Application.OpenForms[0];
        frm.Show();

This is how I open child forms in MDI forms. 这就是我在MDI表单中打开子表单的方式。

// 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);

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM