C#在表单中打开一个程序

时间:2013-02-08 10:59:45

标签: c#

我正在尝试使用以下代码打开一个exe文件。

这是打开我的程序但在表单之外。我希望在我的表单中包含此程序。 请帮忙 此致

Process p = new Process();

p.StartInfo.FileName = @"C:\Program Files\Cadence Design Systems\Allegro Free Physical Viewers 16.6\tools\pcb\bin\allegro_free_viewer";
p.StartInfo.Arguments = "ProcessStart.cs";
p.Start();
p.WaitForExit();
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;

2 个答案:

答案 0 :(得分:2)

您无法使用流程在您的应用程序中运行其他应用程序,您可以使用Object Linking and Embedding执行此操作,并且您要在应用程序中打开的应用程序应该使用ole进行投诉。此代码项目article说明了如何在c#应用程序中嵌入acrobat文档。

答案 1 :(得分:-1)

如果你想说的是你想在Windows窗体应用程序中有一个窗口,那就不容易了。

您最好的选择是设置MDI主机窗口,并使用WinAPI FindWindowSetParent查找外部流程窗口(一旦启动),并将此窗口的父级设置为您的自己的主机窗口。

这样的事情(在导入方法之后)应该有效:

Process p = new Process();

p.StartInfo.FileName = @"C:\Program Files\Cadence Design Systems\Allegro Free Physical Viewers 16.6\tools\pcb\bin\allegro_free_viewer.exe";
p.StartInfo.Arguments = "ProcessStart.cs";
p.Start();
var handle = FindWindow(null, "allegro_free_viewer.exe");
SetParent(handle, this.Handle);
p.WaitForExit();

当然,更好的方法是查看应用程序是否能够提供您能够嵌入到应用程序中的ActiveX / OLE控件,而不是使用外部进程。