문제

I have a windows form that I am displaying as non-modal dialog. As a result I am calling the overloaded Show(IWin32Window owner) method on that form. 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

Argument 1: cannot convert from 'System.Type' to 'System.Windows.Forms.IWin32Window'

Any suggestions on how to achieve this?

도움이 되었습니까?

해결책

You probably will want to search through the Application.OpenForms collection.

Form f = Application.OpenForms.Where(x => x.GetType().Name == "ParentForm").FirstOrDefault();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top