0

我正在尝试以带有以下代码的形式打开一个 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;
4

2 回答 2

2

您不能使用进程在您的应用程序中运行其他应用程序,您可以使用对象链接和嵌入来执行此操作,并且您要从应用程序中打开的应用程序应该与ole. 这篇 codeproject文章解释了如何在 c# 应用程序中嵌入 acrobat 文档。

于 2013-02-08T11:05:24.317 回答
-1

如果您要说的是您希望在 Windows 窗体应用程序中拥有一个窗口,那么这并不容易。

您最好的选择是设置一个 MDI 主机窗口,并使用 WinAPIFindWindowSetParent找到外部进程窗口(一旦启动),然后将此窗口的父级设置为您自己的表单主机窗口。

像这样的东西(在导入方法之后)应该可以工作:

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 控件,而不是使用外部进程。

于 2013-02-08T11:06:26.117 回答