MdiParent Question
-
I have a dialog form and appears on the top of MDIContainer (frmMain) and I want when the user close the dialog form then an MDIChild should be open on the frmMain. I tried: myMDIChild.MdiParent = frmMain(); myMDIChild.Show(); but it didn't work.. I also tried: frmMain MainForm = new frmMain(); myMDIChild.MdiParent = MainForm; myMDIChild.Show(); with no luck. I am not getting any error message but the MDIChild form is not openning.. Many Thanks, Jassim Rahma
-
I have a dialog form and appears on the top of MDIContainer (frmMain) and I want when the user close the dialog form then an MDIChild should be open on the frmMain. I tried: myMDIChild.MdiParent = frmMain(); myMDIChild.Show(); but it didn't work.. I also tried: frmMain MainForm = new frmMain(); myMDIChild.MdiParent = MainForm; myMDIChild.Show(); with no luck. I am not getting any error message but the MDIChild form is not openning.. Many Thanks, Jassim Rahma
-
Hi, In the parent window do the following:
myMDIChild.MdiParent=this; // not frmMain()! MDIChild.Show();
This code has to be called in the frmMain() class. Fred. There is no spoon.but the container is not (this).. i am running this code from frmNew() but the mdi container is frmMain()
-
but the container is not (this).. i am running this code from frmNew() but the mdi container is frmMain()
-
in that case, set the
IsMdiContainer
totrue
and set theMdiParent
property of themyMDIChild
class to the new created form. This should work. Fred. There is no spoon.let me understand.. my main form is frmMain my child form is frmChild the active dialog is frmDialog a user clicked a button which shows a frmDialog and when the user click on the button on the frmDialog it should close it and open frmChild within the container (frmMain) so you want to say in frmDialog i should have this: frmData frmChild = new frmData(); frmChild.MdiParent = frmMain(); frmChild.Show(); I tried that but getting this error: dialog_form.cs(258): 'Ezi_Life.frmMain' denotes a 'class' which is not valid in the given context
-
let me understand.. my main form is frmMain my child form is frmChild the active dialog is frmDialog a user clicked a button which shows a frmDialog and when the user click on the button on the frmDialog it should close it and open frmChild within the container (frmMain) so you want to say in frmDialog i should have this: frmData frmChild = new frmData(); frmChild.MdiParent = frmMain(); frmChild.Show(); I tried that but getting this error: dialog_form.cs(258): 'Ezi_Life.frmMain' denotes a 'class' which is not valid in the given context
Is this what you're looking for? in MDI main form: private void menuItem1_Click(object sender, System.EventArgs e) { DialogForm aDialogFormGUI = new DialogForm(); if (aDialogFormGUI.ShowDialog()== DialogResult.OK) { ThirdForm aThirdFormGUI = new ThirdForm(); aThirdFormGUI.MdiParent = this; aThirdFormGUI.Show(); } } On the Dialog form in the Close event or Click; DialogResult = DialogResult.OK; Hope this helps.
-
Is this what you're looking for? in MDI main form: private void menuItem1_Click(object sender, System.EventArgs e) { DialogForm aDialogFormGUI = new DialogForm(); if (aDialogFormGUI.ShowDialog()== DialogResult.OK) { ThirdForm aThirdFormGUI = new ThirdForm(); aThirdFormGUI.MdiParent = this; aThirdFormGUI.Show(); } } On the Dialog form in the Close event or Click; DialogResult = DialogResult.OK; Hope this helps.
yes.. it worked.. than you very much can i ask one more question please how can i run one instance of MDIChild so that if the user invoked the same option again it will not open a new MDIChild.. t should just bring the already openned MDIChild to front..
-
yes.. it worked.. than you very much can i ask one more question please how can i run one instance of MDIChild so that if the user invoked the same option again it will not open a new MDIChild.. t should just bring the already openned MDIChild to front..
Don't know if this is the best way but... In your MDI Main create a method which passes a temporary Form as a parameter then iterate through all open forms to return the index of the form: int formIndex = -1; int i = 0; foreach (Form cf in this.MDIChildren) { // compare the Form you passed with all open Forms if (passedForm.GetType() == cf.GetType()) { formIndex = i; } i++; } Replace the code in the if statement of the dialogresult to: ThirdForm tempForm = new ThirdForm(); int frmIndex = IndexOfForm(tempForm); tempForm.Dispose(); // The form is not open if(frmIndex == -1) { ThirdForm ThirdFormGUI = new ThirdForm(); ThirdFormGUI.MdiParent = this; ThirdFormGUI.Show(); } // The form is already open else { this.MdiChildren[frmIndex].BringToFront(); }