简体   繁体   English

WinForms:在其他应用程序的主窗口上显示表单模式

[英]WinForms: Show form modal over other application's main window

Is it possible to show a WinForms modal form over another process's main window?是否可以在另一个进程的主窗口上显示 WinForms 模式窗体?

For example my WinForms application consists of one form which is modal over another process's main window with PID x.例如,我的 WinForms 应用程序由一个窗体组成,该窗体在另一个进程的主窗口上是模态的,PID x。

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 .您传递当前IWin32Window或您想成为所有者的form ,因此如果您从父表单上的按钮单击调用它,只需传递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.您希望能够为另一个进程获取IWin32Window ,这是可能的,但我不知道是否将表单显示为模态。

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?此链接可能会提供有关该主题的更多信息: 如何使子进程窗口在我的进程中显示为模态?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM