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. Windows Forms
  4. MDI form with child and child-child forms

MDI form with child and child-child forms

Scheduled Pinned Locked Moved Windows Forms
helpcsharpwinformscomquestion
4 Posts 4 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
    Marcel Vreuls www agentbase nl
    wrote on last edited by
    #1

    Hi All, For a few weeks now i am strungling with an anoying issue. I have a MDI Parent form. From this form i have child forms (normal winforms) which i open. These forms are opened withing the MDI parent form. So far so so good. And know my problem. From this childform i open a new form through a button. There is for me no way to open this form as mdi child form because its parent is also an mdi child. I have looked for looping throug form collections but cannot find the solution to my problem. How can i detect the MDI Parent of my application from within all open forms. Thanks Marcel Vreuls

    Kind regards, Marcel Vreuls MarcelVreuls.com <<A good idea can change your life>>

    M D 2 Replies Last reply
    0
    • M Marcel Vreuls www agentbase nl

      Hi All, For a few weeks now i am strungling with an anoying issue. I have a MDI Parent form. From this form i have child forms (normal winforms) which i open. These forms are opened withing the MDI parent form. So far so so good. And know my problem. From this childform i open a new form through a button. There is for me no way to open this form as mdi child form because its parent is also an mdi child. I have looked for looping throug form collections but cannot find the solution to my problem. How can i detect the MDI Parent of my application from within all open forms. Thanks Marcel Vreuls

      Kind regards, Marcel Vreuls MarcelVreuls.com <<A good idea can change your life>>

      M Offline
      M Offline
      Matt U
      wrote on last edited by
      #2

      Well, since you should know the parent form's class name this is what I've done recently. I can't guarantee that it is the best method of doing it but I also haven't found any other solution:

      // Child form
      private void Button1_Click(object sender, EventArgs e)
      {
      // Do some stuff
      // ...

      // Now open a new child form by calling a method in the MDI parent form
      ((AppForm)this.MdiParent).SomeMethodToOpenChild();
      

      }

      Casting the current child form's 'Form MdiParent' to the application's form type, then calling a method that opens the necessary child window. Like I said, I don't know how safe that is. But I believe you could check ahead of time like this:

      if (this.MdiParent is AppForm)
      ((AppForm)this.MdiParent).SomeMethodToOpenChild();

      I hope this at least gets you going in the right direction. :-)

      1 Reply Last reply
      0
      • M Marcel Vreuls www agentbase nl

        Hi All, For a few weeks now i am strungling with an anoying issue. I have a MDI Parent form. From this form i have child forms (normal winforms) which i open. These forms are opened withing the MDI parent form. So far so so good. And know my problem. From this childform i open a new form through a button. There is for me no way to open this form as mdi child form because its parent is also an mdi child. I have looked for looping throug form collections but cannot find the solution to my problem. How can i detect the MDI Parent of my application from within all open forms. Thanks Marcel Vreuls

        Kind regards, Marcel Vreuls MarcelVreuls.com <<A good idea can change your life>>

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        If the form is an MdiChild, you can get a reference to its parent using the MdiParent property. If you want to set another form as a child of the same parent, it's pretty easy If you want a MdiChild form to be both a MdiChild to one Parent and a MdiParent to another child form, you can't. It's not supported. A form cannot be both a MdiChild and MdiParent at the same time.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        R 1 Reply Last reply
        0
        • D Dave Kreskowiak

          If the form is an MdiChild, you can get a reference to its parent using the MdiParent property. If you want to set another form as a child of the same parent, it's pretty easy If you want a MdiChild form to be both a MdiChild to one Parent and a MdiParent to another child form, you can't. It's not supported. A form cannot be both a MdiChild and MdiParent at the same time.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          R Offline
          R Offline
          Richard Blythe
          wrote on last edited by
          #4

          Great answer Dave. :thumbsup:

          The mind is like a parachute. It doesn’t work unless it’s open.

          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