Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在表单中运行exe?_C#_.net_Visual Studio - Fatal编程技术网

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文件?