[英]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.