简体   繁体   English

如何使用反射获取表单的IWin32Window

[英]how to get IWin32Window of form using reflection

I have a windows form that I am displaying as non-modal dialog. 我有一个Windows窗体,我显示为非模态对话框。 As a result I am calling the overloaded Show(IWin32Window owner) method on that form. 因此,我在该窗体上调用重载的Show(IWin32Window所有者)方法。 Only problem is that one of the parent forms that I want to use here is not accessible in the project. 唯一的问题是我想在这里使用的父表单之一在项目中是不可访问的。 As a result I want to load it using reflection using something like code below. 因此,我想使用反射使用类似下面的代码加载它。

var frm = Assembly.GetEntryAssembly().GetTypes().Where(f => f.Name == "ParentForm").FirstOrDefault();

However this give following compilation errors. 但是,这会产生以下编译错误。

The best overloaded method match for 最好的重载方法匹配

'System.Windows.Forms.Form.Show(System.Windows.Forms.IWin32Window)' has some invalid arguments 'System.Windows.Forms.Form.Show(System.Windows.Forms.IWin32Window)'有一些无效的参数

Argument 1: cannot convert from 'System.Type' to 'System.Windows.Forms.IWin32Window' 参数1:无法从'System.Type'转换为'System.Windows.Forms.IWin32Window'

Any suggestions on how to achieve this? 有关如何实现这一目标的任何建议?

您可能希望搜索Application.OpenForms集合。

Form f = Application.OpenForms.Where(x => x.GetType().Name == "ParentForm").FirstOrDefault();

暂无
暂无

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

相关问题 WPF 等效于 Form.ShowDialog(IWin32Window) - WPF equivalent of Form.ShowDialog(IWin32Window) C# 中的 IWin32Window? - IWin32Window in C#? Form.ShowDialog(IWin32Window) 是否应该与任何 window 句柄一起使用? - Should Form.ShowDialog(IWin32Window) work with any window handle? 从另一个类打开通用表单会导致IWin32Window转换错误 - Opening a generic form from another class causes a IWin32Window conversion error C#WinForms:在另一个线程中具有IWin32Window owner参数的Form.ShowDialog() - C# WinForms: Form.ShowDialog() with IWin32Window owner parameter in a different thread Excel VSTO中的Form.Show(IWin32Window)方法在应用程序关闭时导致ThreadAbortException - Form.Show(IWin32Window) method in Excel VSTO causing ThreadAbortException on application close 如何在SetCompatibleTextRenderingDefault抛出InvalidOperationException时找出IWin32Window已创建的内容? - How to find out what IWin32Window has been created when SetCompatibleTextRenderingDefault throws an InvalidOperationException? 在特定条件下如何显示或隐藏工具提示? IWin32window赢了吗? - How to show or hide a tooltip under specific conditions? IWin32window win? 在VSTO外接程序中将IWin32Window父句柄获取到中心saveFileDialog - Get IWin32Window Parent Handle in VSTO Addin to Center saveFileDialog .Owner属性和ShowDialog(IWin32Window所有者)之间的区别? - Difference between .Owner property and ShowDialog(IWin32Window owner)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM