Open an external application INSIDE the form or panel

PHOTO EMBED

Wed Mar 01 2023 18:48:44 GMT+0000 (Coordinated Universal Time)

Saved by @dhfinch #c#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace externalapp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog od = new OpenFileDialog();      //
            if (od.ShowDialog() == DialogResult.OK)        //
            {                                              //   
               // Process proc = Process.Start(@"give your program address here");
                Process proc = Process.Start(od.FileName);  //
                proc.WaitForInputIdle();

                while(proc.MainWindowHandle== IntPtr.Zero) 
                {
                    Thread.Sleep(100);
                    proc.Refresh();
                }

                //SetParent(proc.MainWindowHandle, this.panel1.Handle);
                SetParent(proc.MainWindowHandle, this.Handle);
            }                                              //
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
content_copyCOPY

https://www.youtube.com/watch?v=KvHZxprWVO8