C#创建窗口 – 定义父窗口
发布时间:2020-12-15 08:20:43 所属栏目:百科 来源:网络整理
导读:我想创建使用C#窗口,设置父级到我定义的句柄, 这是另一个进程窗口句柄. 有人知道怎么做吗? 问候, 解决方法 如果我正确地理解了你的问题,你应该能够通过使用这样的东西来实现你想要的东西: class Win32Window : IWin32Window{ IntPtr handle; public Win32W
我想创建使用C#窗口,设置父级到我定义的句柄,
这是另一个进程窗口句柄. 有人知道怎么做吗? 问候, 解决方法
如果我正确地理解了你的问题,你应该能够通过使用这样的东西来实现你想要的东西:
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知识并不是那么好. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |