Reputation: 34026
i am trying to get the main form of a process that i started, but the FromChildHandle and FromHandle always return null. the MainWindowHandle however is nonzero.
IntPtr p = process_wrapper.MainWindowHandle;
Form form = (Form) Control.FromChildHandle(p);
if (form != null)
{
form.Close();
}
Upvotes: 7
Views: 172
Reputation: 20899
You can only retrieve a form as a control, if the form in question has been generated by your application. You cannot retrieve a form from another process, as your parent process is not aware of the handle <->Control mapping of the child process.
If you just want to "stop" the child process (form.close()
?) You can simple stop the complete process. Either "Clean", or by force:
process.CloseMainWindow()
vs process.kill()
Upvotes: 2