MdiParent and InvokeMember...

G

Guest

How can I get a form in a class library to become an MDI Child of the main
application? I've tried the following, but does not work:

Class Library...
public class Class1
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}
public static bool
DisplayForm(System.Windows.Forms.Form theMDIParent)
{
Form1 f = new Form1();
f.MdiParent = theMDIParent;
f.ShowDialog();
f.Close();
return true;
}
}

In Main App...
Assembly asm = Assembly.LoadFile(@"c:\Documents and Settings\rvasquez\My
Documents\Visual Studio
Projects\TestMDIForms\OtherForms\bin\debug\OtherForms.dll");
Type t = asm.GetType("OtherForms.Class1");
object result = null;
object[] arguments = {this};
result = t.InvokeMember("DisplayForm",BindingFlags.InvokeMethod, null,
result, arguments);
 
M

Martin Stainsby

possibly setting f.TopLevel = false; may be neccesary, it is when immitating
mdi on a normal form. Also and also guessing it mght be neccesary to set the
mdiclient as the parent rather than setting mdiparent. I did a immitation
mdi app that needed this behaviour to get a form to act as a child form,
whether it works with a proper mdi app I can only guess at.

Hope something is useful.

Martin.
 
G

Guest

Martin, thank you for your reply. I found out my mistake to be the
following...

f.ShowDialog();

instead of...

f.Show();

Martin Stainsby said:
possibly setting f.TopLevel = false; may be neccesary, it is when immitating
mdi on a normal form. Also and also guessing it mght be neccesary to set the
mdiclient as the parent rather than setting mdiparent. I did a immitation
mdi app that needed this behaviour to get a form to act as a child form,
whether it works with a proper mdi app I can only guess at.

Hope something is useful.

Martin.

Robert Vasquez said:
How can I get a form in a class library to become an MDI Child of the main
application? I've tried the following, but does not work:

Class Library...
public class Class1
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}
public static bool
DisplayForm(System.Windows.Forms.Form theMDIParent)
{
Form1 f = new Form1();
f.MdiParent = theMDIParent;
f.ShowDialog();
f.Close();
return true;
}
}

In Main App...
Assembly asm = Assembly.LoadFile(@"c:\Documents and Settings\rvasquez\My
Documents\Visual Studio
Projects\TestMDIForms\OtherForms\bin\debug\OtherForms.dll");
Type t = asm.GetType("OtherForms.Class1");
object result = null;
object[] arguments = {this};
result = t.InvokeMember("DisplayForm",BindingFlags.InvokeMethod, null,
result, arguments);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top