Running exe inside WinForm Project Tab

做~自己de王妃 提交于 2019-11-30 07:41:18

You could use the SetParent api to set the parent of the executable's window. Add a panel to your TabControl and use the code below to assign the parent of the executable window to that of the panel.

[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);
}

To remove the window from the panel, use the same code but set the parent handle as IntPtr.Zero

SetParent(process.MainWindowHandle, IntPtr.Zero);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!