C# 如何在表单中运行exe?
我已经搜索了所有地方,并将其合并到我的代码中:C# 如何在表单中运行exe?,c#,.net,visual-studio,C#,.net,Visual Studio,我已经搜索了所有地方,并将其合并到我的代码中: Process process = new Process(); process.StartInfo.FileName = exePath; //this is a valid path process.Start(); Thread.Sleep(500); process.WaitForInputIdle(); SetParent(process.MainWindowHandle, this.Handle); 但是,它通常在自己的窗口中启动程
Process process = new Process();
process.StartInfo.FileName = exePath; //this is a valid path
process.Start();
Thread.Sleep(500);
process.WaitForInputIdle();
SetParent(process.MainWindowHandle, this.Handle);
但是,它通常在自己的窗口中启动程序,而不是在我的主窗体中。我找到了一个可能的解决方案 我还没有测试代码 您需要确保在父窗体上将IsMdiContainer设置为true 以下是实施方案:
Form child = new Form();
Assembly asm = Assembly.LoadFile("c:\\executablefile.exe ");
Type type = asm.GetType("WindowsForm", true, true);
object childform = Activator.CreateInstance(type);
child = (Form)childform;
child.MdiParent = this;
child.Show();
该程序是控制台/文本程序吗?您正在尝试运行哪种类型的exe文件?