Running exe inside WinForm project tab

I am interested in helping with the following steps using the winform application that I am writing to open on the .exe tab in C # in the Visual Studio 2010 IDE.

Currently, I can open the program by clicking the button on the desired tab using the following code:

        string str = @"-INSERT FILEPATH HERE-";//took file path out as i have a few exes i'm wanting to add. 
        Process process = new Process();
        process.StartInfo.FileName = str;
        process.Start();

Now how can I make this executable open as a tab or tab in my winform? I am open to suggestions to do all things.

SOLVE:

using System.Runtime.InteropServices;
    using System.Threading;
    [DllImport("user32.dll", SetLastError = true)]
    private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

   public GUI()
    {
        // Initialize form fieds
        InitializeComponent();
        openProgram()
    }
    private void openProgram()
    {

        process.StartInfo.FileName = "-filepathhere-";

        process.Start();

        IntPtr ptr = IntPtr.Zero;
        while ((ptr = process.MainWindowHandle) == IntPtr.Zero) ;
        SetParent(process.MainWindowHandle, trackerPanel.Handle);
        MoveWindow(process.MainWindowHandle, 0, 0, this.Width - 90, this.Height, true);

    }
+3
source share
1 answer

SetParent api . TabControl , , .

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

private void button2_Click(object sender, EventArgs e)
{
    var process = new Process();
    process.StartInfo.FileName = "notepad.exe";
    process.Start();
    SetParent(process.MainWindowHandle, panel1.Handle);
}

, , IntPtr.Zero

SetParent(process.MainWindowHandle, IntPtr.Zero);
+3

Source: https://habr.com/ru/post/1650030/


All Articles