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, MDIChild and MDI..ermmm..GrandChild? (How to set the MDIParent on a form that is called through a child form?)

MDIParent, MDIChild and MDI..ermmm..GrandChild? (How to set the MDIParent on a form that is called through a child form?)

Scheduled Pinned Locked Moved C#
helptutorialquestion
5 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.
  • M Offline
    M Offline
    MNantu
    wrote on last edited by
    #1

    Hi everyone, I have a little problem and I feel like the solution is in front of me but I just can't make it happen. I haven't googled it yet, just because i don't know how to search it, but I'm looking for it in the MSDN Forums (Searched MDI in forums and reading the topics whichever looks close to solution.) and I was unable to find something for the problem. The problem is I have an MDI form and I show a dialog which offers you some options and when the user clicks the button a new dialog appears.But I couldn't find a way to set the MDIParent property for the form that is called from the child.So the new form appears independent from the MDIParent. What I've tried is: I tried overloading the Form.Show(this.MDIParent) I've created an instance of the MDI form in the Grandchild(?) form. I've tried to set the this.MDIParent = MDIMain but it just didn't work. I've tried this.AddOwnedForm(Form) So, surprisingly, none of them worked. It'd be really nice if you could help me through or hold my hand and take me to the neverland. =) Thanks.

    S 1 Reply Last reply
    0
    • M MNantu

      Hi everyone, I have a little problem and I feel like the solution is in front of me but I just can't make it happen. I haven't googled it yet, just because i don't know how to search it, but I'm looking for it in the MSDN Forums (Searched MDI in forums and reading the topics whichever looks close to solution.) and I was unable to find something for the problem. The problem is I have an MDI form and I show a dialog which offers you some options and when the user clicks the button a new dialog appears.But I couldn't find a way to set the MDIParent property for the form that is called from the child.So the new form appears independent from the MDIParent. What I've tried is: I tried overloading the Form.Show(this.MDIParent) I've created an instance of the MDI form in the Grandchild(?) form. I've tried to set the this.MDIParent = MDIMain but it just didn't work. I've tried this.AddOwnedForm(Form) So, surprisingly, none of them worked. It'd be really nice if you could help me through or hold my hand and take me to the neverland. =) Thanks.

      S Offline
      S Offline
      Shpendh
      wrote on last edited by
      #2

      hi there, i think this will help from the first form you have to raise an event (on click of something ex. button) and you write this code : Form frm = new Form(); frm.MdiParent = this; frm.Show(); and i will depend on that form, from where it was opened, respect.

      spaps

      M 1 Reply Last reply
      0
      • S Shpendh

        hi there, i think this will help from the first form you have to raise an event (on click of something ex. button) and you write this code : Form frm = new Form(); frm.MdiParent = this; frm.Show(); and i will depend on that form, from where it was opened, respect.

        spaps

        M Offline
        M Offline
        MNantu
        wrote on last edited by
        #3

        Hi Shpends, Thanks for the quick reply. But it seems to me that your code shows up a child form.What I need is showing a child form that is called from the previous child. I mean, if we call the first child form X and second child form Y, I try showing Y through X and I can't set the MDIParent property because I call it from an MDIChild form not from the MDIParent itself. I hope the explanation above is clear enough. =) Thanks again.

        D 1 Reply Last reply
        0
        • M MNantu

          Hi Shpends, Thanks for the quick reply. But it seems to me that your code shows up a child form.What I need is showing a child form that is called from the previous child. I mean, if we call the first child form X and second child form Y, I try showing Y through X and I can't set the MDIParent property because I call it from an MDIChild form not from the MDIParent itself. I hope the explanation above is clear enough. =) Thanks again.

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          Try this... In the MDIParent (Form1)

          private void Form1_Load(object sender, EventArgs e)
          {
          Form2 newForm = new Form2(this);
          newForm.MdiParent = this;
          newForm.Show();
          }

          for 1st Child (Form2)...

          public Form2(Form mdiParent)
          {
          InitializeComponent();
          _mdiParent = mdiParent;
          }

              private Form \_mdiParent;
          
              private void Form2\_Load(object sender, EventArgs e)
              {
                  Form3 newForm = new Form3();
                  newForm.MdiParent = \_mdiParent;
                  newForm.Show();
              }
          

          with Form3 being the 2nd Child. Obviously you need to dispose of the forms somewhere but should get you going.

          M 1 Reply Last reply
          0
          • D DaveyM69

            Try this... In the MDIParent (Form1)

            private void Form1_Load(object sender, EventArgs e)
            {
            Form2 newForm = new Form2(this);
            newForm.MdiParent = this;
            newForm.Show();
            }

            for 1st Child (Form2)...

            public Form2(Form mdiParent)
            {
            InitializeComponent();
            _mdiParent = mdiParent;
            }

                private Form \_mdiParent;
            
                private void Form2\_Load(object sender, EventArgs e)
                {
                    Form3 newForm = new Form3();
                    newForm.MdiParent = \_mdiParent;
                    newForm.Show();
                }
            

            with Form3 being the 2nd Child. Obviously you need to dispose of the forms somewhere but should get you going.

            M Offline
            M Offline
            MNantu
            wrote on last edited by
            #5

            Hi DaveyM69, Thank you very much for your help. It works just fine. Thanks again.

            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