Shayne T. Thiessen
Shayne T. Thiessen

Reputation: 57

How do I open an executable as a MDI child?

I have a parent form that starts another application. When the application starts it should set the application as an mdichild of parent.

I have managed to get this to work with notepad using the code below.

Process proc = new Process();

proc.StartInfo.FileName = "notepad.exe";
proc.Start();
proc.WaitForInputIdle();
SetParent(proc.MainWindowHandle, this.panel.Handle);

The problem is that it doesn't work with all applications. Specifically it doesn't work with other win forms applications developed in c#, which is what I need it for.

Any help is appreciated, Thanks.

Edit: I have access to the code for the c# app i want to open as a mdi child.

Upvotes: 3

Views: 2339

Answers (2)

Zülkarneyn
Zülkarneyn

Reputation: 9

  1. add .exe(for example another.exe) file as reference
  2. add another.exe references // may be differ from your mdi form
  3. add below code another.Form1 fr = new another.Form1(); //another.exe has Form1 if not select form. fr.MdiParent = this; fr.Show(); // Display the new form.

Upvotes: 0

Reza Aghaei
Reza Aghaei

Reputation: 125292

OP: I have access to the code for the c# app i want to open as a mdi child.

To open a form of other .Net windows application, you don't need to use SetParent and you can simply add a reference of that .Net Application (dll, exe or project) to your current project and then create an instance of the main form of that application and show it like other forms of your application.

  • If you have access to project of that application, you can add it to your current solution and use add a reference to your current project.

  • If you don't have access to project of the project of that application, you can add a reference to its exe/dll to your current project.

To learn more about add reference, read How to: Add or Remove References By Using the Add Reference Dialog Box

Upvotes: 1

Related Questions