【发布时间】:2020-06-29 15:15:47
【问题描述】:
我使用 Process.Start() 从我的程序中打开了一个 Chrome 浏览器窗口,但新打开的 chrome 浏览器选项卡覆盖了屏幕。但我希望我的应用程序在创建这些 chrome 浏览器选项卡后保持其焦点。
我将打开一个浏览器窗口,但有几个 chrome 选项卡显示不同的 URL。
这是我尝试过的,类似于How to set focus back to form after opening up a process (Notepad)? 的答案。但对我不起作用。
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd)
// this code will get called several times with a different URL in Arguments property
Process p = new Process();
p.StartInfo = new ProcessStartInfo("Chrome.exe");
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = "https:/google.com";
p.Start();
p.WaitForInputIdle();
SetForegroundWindow(this.Handle);
【问题讨论】: