I have a System.Diagnostics.Process variable named _program.
I understand that not every process have a user interface, so it will never have a focus (I think).
But, supposing that this process has a interface, is it possible to set focus to it ? Maybe I need to use Process.StandardInput?
Asked
Active
Viewed 133 times
0
Vinícius Velloso
- 3
- 1
-
2Possible duplicate of [Correct way (in .NET) to switch the focus to another application](https://stackoverflow.com/questions/2315561/correct-way-in-net-to-switch-the-focus-to-another-application) – Oct 10 '18 at 18:27
1 Answers
1
Use PInvoke to call a native function to set the foreground window:
using System.Runtime.InteropServices;
DllImport("User32.dll")]
private static extern Int32 SetForegroundWindow(int hWnd);
void YourMethod()
{
Process p = ... //However you create your process
SetForegroundWindow(p.MainWindowHandle); //Set this process's main window as the foreground window
}
MikeH
- 4,043
- 17
- 31