MdiParent problem [modified]
-
Iam working on MDI application and I have some problem. For the main form, IsMdiContainer is set to true as well as the MdiParent for child form, is set to 'this' (main form). But problem starts here. I put all the codes for each controls in each separete class so it's easy to manipulate. In Tabs class, I have all the methods, properties I need for adding, removing, renaming etc. tabs. I also have a method for adding new child forms. In this method, MdiParent isn't set to 'this', but to frmMain.ActiveForm. The thing is that everything works great unless I try to add new tab from the other Form. App then breaks at line MdiParent = frmMain.ActiveForm with this error:
Form that was specified to be the MdiParent for this form is not an MdiContainer. Parameter name: value.
How can I workaround this problem, but still have this method for adding new child forms in Tabs class? Iam out of ideas. Sorry if my post is confusing. -
Iam working on MDI application and I have some problem. For the main form, IsMdiContainer is set to true as well as the MdiParent for child form, is set to 'this' (main form). But problem starts here. I put all the codes for each controls in each separete class so it's easy to manipulate. In Tabs class, I have all the methods, properties I need for adding, removing, renaming etc. tabs. I also have a method for adding new child forms. In this method, MdiParent isn't set to 'this', but to frmMain.ActiveForm. The thing is that everything works great unless I try to add new tab from the other Form. App then breaks at line MdiParent = frmMain.ActiveForm with this error:
Form that was specified to be the MdiParent for this form is not an MdiContainer. Parameter name: value.
How can I workaround this problem, but still have this method for adding new child forms in Tabs class? Iam out of ideas. Sorry if my post is confusing.Hi, ActiveForm is a static property of the Form class that returns currently activated form for the application but not the acitve frmMain instance. So in some cases you try to bind child form to the non-MDI-parent form. To have access to your frmMain form from all your classes you can add static property to it (as in the Singleton pattern):
class frmMain
{
private static frmMain current;
public static frmMain Current
{
get
{
return current;
}
}
public frmMain()
{
// constructor logic here
current = this;
}
}Then you can use this property to construct your MDI-child forms:
childForm.MDIParent = frmMain.Current;
-
Hi, ActiveForm is a static property of the Form class that returns currently activated form for the application but not the acitve frmMain instance. So in some cases you try to bind child form to the non-MDI-parent form. To have access to your frmMain form from all your classes you can add static property to it (as in the Singleton pattern):
class frmMain
{
private static frmMain current;
public static frmMain Current
{
get
{
return current;
}
}
public frmMain()
{
// constructor logic here
current = this;
}
}Then you can use this property to construct your MDI-child forms:
childForm.MDIParent = frmMain.Current;
Thank you Andrew, very much. It works like a clock. I've tried something similar, but mine wouldn't work :). I've used other class for this, and it happened nothing, no error, no action, no anything :). And again, thanks.