Frage

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?

War es hilfreich?

Lösung

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

Form f = Application.OpenForms.Where(x => x.GetType().Name == "ParentForm").FirstOrDefault();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top