考慮到您使用的是面板,你的進程中.. 您可以使用此行代碼
ProcessStartInfo info = new ProcessStartInfo();
Process p = new process(); // you can also use System.Diagnostics.Process
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = // your Process
info.Arguments = "Your Argument";
info.UseShellExecute = true;
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Maximized; //this will make no effect, so optional
info.RedirectStandardInput = false;
info.RedirectStandardOutput = false;
info.RedirectStandardError = false;
p = System.Diagnostics.Process.Start(info);
p.WaitForInputIdle();
Thread.Sleep(10000);
SetParent(p.MainWindowHandle, this.pnlAlpha.Handle);
// You also need to use this line so that your window should be re-sized
MoveWindow(p.MainWindowHandle, 0, 0, yourPanel.Width, yourPanel.Height, true);
//Dont forget to add this globally
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("USER32.dll")]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
你在談論Windows窗體或Windows服務?你說服務,但是服務通常不包含UI。 – BentOnCoding
也許它會更好,使myApp.exe採取一些命令行參數和調整自己 - 沒有等待,沒有奇怪的看 – Yahia
在旁邊注意'Thread.Sleep(2000)'讓我畏縮。有沒有一種方法可以測試窗口是否加載並循環,直到發生這種情況? –