Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. MdiParent Question

MdiParent Question

Scheduled Pinned Locked Moved C#
helpquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    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

    B 1 Reply Last reply
    0
    • J 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

      B Offline
      B Offline
      bouli
      wrote on last edited by
      #2

      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.

      J 1 Reply Last reply
      0
      • B bouli

        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.

        J Offline
        J Offline
        Jassim Rahma
        wrote on last edited by
        #3

        but the container is not (this).. i am running this code from frmNew() but the mdi container is frmMain()

        B 1 Reply Last reply
        0
        • J Jassim Rahma

          but the container is not (this).. i am running this code from frmNew() but the mdi container is frmMain()

          B Offline
          B Offline
          bouli
          wrote on last edited by
          #4

          in that case, set the IsMdiContainer to true and set the MdiParent property of the myMDIChild class to the new created form. This should work. Fred. There is no spoon.

          J 1 Reply Last reply
          0
          • B bouli

            in that case, set the IsMdiContainer to true and set the MdiParent property of the myMDIChild class to the new created form. This should work. Fred. There is no spoon.

            J Offline
            J Offline
            Jassim Rahma
            wrote on last edited by
            #5

            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

            D 1 Reply Last reply
            0
            • J Jassim Rahma

              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

              D Offline
              D Offline
              dmccabe2
              wrote on last edited by
              #6

              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.

              J 1 Reply Last reply
              0
              • D dmccabe2

                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.

                J Offline
                J Offline
                Jassim Rahma
                wrote on last edited by
                #7

                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..

                D 1 Reply Last reply
                0
                • J Jassim Rahma

                  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..

                  D Offline
                  D Offline
                  dmccabe2
                  wrote on last edited by
                  #8

                  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(); }

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups