Reputation: 743
Is it possible to show a WinForms modal form over another process's main window?
For example my WinForms application consists of one form which is modal over another process's main window with PID x.
Upvotes: 12
Views: 35892
Reputation: 7475
You can show it as a dialog, like so:
Form1 frm = new Form1();
frm.ShowDialog(this);
frm.Dispose();
You pass the current IWin32Window
or form
you want to be the owner, so if you're calling it from say a button click on the parent form, just pass through this
.
You want to be able to get the IWin32Window
for another process, which is possible, but I don't know if showing a form as a modal over that is.
var proc = Process.GetProcesses().Where(x => x.ProcessName == "notepad").First();
IWin32Window w = Control.FromHandle(proc.MainWindowHandle);
using (Form1 frm = new Form1())
{
frm.ShowDialog(w);
}
This is how it would work, if it was possible, however, it doesn't seem to work for me.
This link may shed a bit more information on the subject: How can I make a child process window to appear modal in my process?
Upvotes: 20