C# open other program in form panel


Hello I am a beginner developer in Korea.

I'm making. Program. The program runs three exe (developed in c ++, c #) on one form and puts the program into the panel.

Now I put the program in C ++ or other languages into the panel. However, windows programs built with C # do not keep on the panel. Here is part of my code:

    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
    static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

    static extern bool MoveWindow(IntPtr Handle, int x, int y, int w, int h, bool repaint);

    static readonly int GWL_STYLE = -16;
    static readonly int WS_VISIBLE = 0x10000000;

    private void Form1_Load(object sender, EventArgs e)

            Process p = Process.Start("C:\\Users\\sonmi\\OneDrive\\Japan_Bunge_alpha\\Japan_Bunge_alpha\\bin\\Debug\\Japan_Bunge_alpha"); //C# program
            Process p2 = Process.Start("C:\\Users\\sonmi\\Desktop\\astana_test\\astana\\Server\\Server_CES"); //C++ program


            SetParent(p.MainWindowHandle, this.Handle);
            SetWindowLong(p.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
            MoveWindow(p.MainWindowHandle, 0, 0, panel1.Width, panel1.Height, true);

            SetParent(p2.MainWindowHandle, panel2.Handle);
            SetWindowLong(p2.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
            MoveWindow(p2.MainWindowHandle, 0, 0, panel2.Width, panel2.Height, true);


I have used two panels now, but I will add more after this test is over. I don't know where the problem is.

asked on Stack Overflow Nov 5, 2017 by Minsoo Son

2 Answers


For the C# application, you can load the application into the current AppDomain and treat it like a library. Add it to your project references for this. How you would initialize and put it into your panel would depend on how the referenced application is designed.

You might have to initialize the main form for that application yourself and set parent that way.

answered on Stack Overflow Nov 5, 2017 by Brett Allen
SetParent(p.MainWindowHandle, this.Handle); <-- panel1.Handle
SetWindowLong(p.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
answered on Stack Overflow Jun 13, 2019 by kimcoder • edited Jun 13, 2019 by barbsan

User contributions licensed under CC BY-SA 3.0