2013-02-08 13 views
0

我正試圖用下面的代碼在窗體中打開一個exe文件。C#打開一個表格中的程序

這是打開我的程序,但在窗體外。我想要在我的窗體中有這個程序。 請幫助 問候

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; 
+1

「我的表格裏面有這個程序」是什麼意思? – VladL

+0

爲什麼需要在表單中打開「內部」? – Arran

+0

嗨,我在C#中創建窗體,然後我想執行阿德羅戈程序,但程序要在我的窗體內打開。 – Sorin

回答

2

你不能使用你的程序應用程序中運行的其它應用,你可以用Object Linking and Embedding做到這一點,你想從你的應用程序中打開應用程序應該是投訴ole。此代碼項目article說明了如何在c#應用程序中嵌入acrobat文檔。

-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控件嵌入到您的應用程序中,而不是使用外部過程。

+0

-1爲一個解決方案,實際上*會*允許他嵌入一個應用程序在他自己的? –