0

I need to open third party .exe file inside windows form. I am using this code but it will open another new windows outside the form.

[DllImport("user32.dll")]  
 static extern IntPtr setParent(IntPtr hwc, IntPtr hwp);  

private void panel1_Paint(object sender, PaintEventArgs e)  
        {  
            Process p = Process.Start("notepad.exe");  
            Thread.Sleep(5000);  
            p.WaitForInputIdle();  
            setParent(p.MainWindowHandle, this.Handle);  
        }  

Right now I am opening this notepad.exe in panel view but it will not open inside in form it will open in outside the form.

Please let me know how to do this.

Thanks in advance.

Steve
  • 213,761
  • 22
  • 232
  • 286
  • 3
    Starting a Process in the a Paint event is asking for troubles. – Steve Jan 18 '17 at 19:19
  • I don't think you can run an application inside a windows form. Why would you do that? – abc Jan 18 '17 at 19:20
  • You can't open another process' window *inside* your own window. It's not going to work like that. –  Jan 18 '17 at 19:21
  • 3
    Your code works for me. C# is case sensitive. The function in user32.dll is called "SetParent" ... change case and try again. I have notepad opened up inside of a windows form with only that change. But please look at the top comment. It's not smart to start a process in paint - the form paints very, very frequently. You'll more than likely wind up with a stackoverflow, or numerous notepad's at a minimum. – Aaron Jan 18 '17 at 19:26
  • [This solution works fine for me](http://stackoverflow.com/questions/5836176/docking-window-inside-another-window) – Vepa Durdiyev Jan 18 '17 at 21:45

0 Answers0