【发布时间】:2011-09-03 00:05:55
【问题描述】:
我想使用 C# 窗口创建,并将父窗口设置为我定义的句柄,
这是另一个进程窗口句柄。
有人知道怎么做吗?
您好,
【问题讨论】:
标签: c# wpf windows createwindow
我想使用 C# 窗口创建,并将父窗口设置为我定义的句柄,
这是另一个进程窗口句柄。
有人知道怎么做吗?
您好,
【问题讨论】:
标签: c# wpf windows createwindow
如果我正确理解了您的问题,您应该能够通过使用以下内容来实现您想要的:
class Win32Window : IWin32Window
{
IntPtr handle;
public Win32Window(IntPtr handle) { this.handle = handle; }
public IntPtr Handle
{
get { return this.handle; }
}
}
static void Main()
{
IntPtr targetParent = // Get handle to the parent window
new MainForm().ShowDialog(new Win32Window(targetParent));
}
这将使MainForm 成为指定窗口的子窗口,使其始终显示在其上方。我在示例中使用ShowDialog,但这也适用于Show。这是特定于 Windows 窗体的。
在 WPF 中,您可以尝试以下操作:
var helper = new WindowInteropHelper(/* your Window instance */);
helper.Owner = // Set with handle for the parent
我在显示 WPF 窗口后很快尝试了这个,它似乎按预期工作,但是 WPF 知识并不是那么好。
【讨论】: