Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to run a window form application from another running window form application? If possible, then please help.Thanks
Posted
Updated 1-May-11 20:22pm
v2

Pong provided the answer.
However, in this way the two processes cannot communicate.

I feel that you mean running one application inside the form of another one. If you don't have source code of both applications, it is not easy. If you have source codes, best you can do is re-work the code the way they run in one application and one process.

If you don't have the source code of "guest" or "child" application, I do not recommend addressing this problem — the good results are not guaranteed and hard to achieve.

1) You can run "child" application as a child process via System.Diagnostic.Process, get windows handles of the main forms of both application (use Process.MainWindowHandle to get the one of the child process) and P/Invoke and use Windows API function SetParent. The result depends on how child application works — this trick can be disruptive.

2) You can use Reflection to extract the class of the main form of using the "guest" application assembly of loaded through System.Reflection.Assembly.LoadFrom. You can try to get the class of it's main form, instantiate it and add to your application's Application through Form.Show. In this way, you will have only one process, which is always better. The second assembly will be used as the library, not as a separate application with its own process. Solving this problem is not very easy and also could be disruptive to the functionality of the second assembly.

Again, trying any of those approaches is a matter of research. In certain cases it will work. In the general case the result is not guaranteed.

—SA
 
Share this answer
 
v3
Comments
Pong D. Panda 2-May-11 2:50am    
With your solution, i dont think he can comprehend it, worst is you make his head explode. Anyways, good tip, learned something new today. My 5
Sergey Alexandrovich Kryukov 2-May-11 4:05am    
Thank you, Pong. I cannot take responsibility for sanity of one's head :-). OP can always ask a follow-up questions anyway. It's hard to provide a full solution of this complexity in a short answer.
--SA
Yes it is. Try something like this.

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName="c:\\codeproject\\test.exe";
proc.Start();
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-May-11 2:44am    
Good enough, this could work but is not very useful. Not your fault -- nmy 5 anyway.

I feel OP needs one application running inside the other one (because it is the usual question that was already answered few times).

So, please see my answer -- it's pretty interesting, not so practical though...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900