Results 1 to 7 of 7

Thread: Child form in front of the controls on parent form

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2022
    Posts
    15

    Child form in front of the controls on parent form

    Hi!

    I have a parent form with a panel and some buttons and labels.
    Then I have a child form which is shown by clicking on a button on the parent form.

    However, when the child form is shown, it is in front of the parent form, but behind the buttons and all of that.
    How do I change this, so that the child form is in front of everything?

    Code:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim frm1 As New Form3
    frm1.MdiParent = Me
    frm1.TopMost = True
    frm1.Show()

    (I have also tried using " frm1.BringToFront ", but doesn't help...)

    Thanks!

  2. #2

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2022
    Posts
    15

    Re: Child form in front of the controls on parent form

    Thanks, that works great!

    Now I just have to make it stay inside the former parent form.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Child form in front of the controls on parent form

    Quote Originally Posted by Anderskd1 View Post
    How do I change this, so that the child form is in front of everything?
    You don't if you're using MDI. It helps to know how MDI works. When you set isMdiParent to True, an MdiClient control is added to the form. That's what has the grey background that you see. When you add an MDI child form, it is hosted within that MdiClient control. If you add any other controls to the form, they will ALWAYS be displayed in front of that MdiClient control, which means that they will ALWAYS be displayed in front of MDI child forms. It is physically impossible to do what you want to do. You would have to NOT use MDI and add the child forms to the parent as regular controls. The question is why you're doing that at all. Why would you want a form inside another form and over the controls on that parent form? I can't think of a situation where that's not bad UX.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Child form in front of the controls on parent form

    That is a strange design. I can’t think of a situation where that would be a good design decision…
    Perhaps you should explain why you want to do that?

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Child form in front of the controls on parent form

    The the "Me" in form1.Show(Me) is a simple way to make it the Owner of form1.

    The owned form is locked in front of the owner (and its child controls) in the Z order, so no other form can come between them. If you close, show/hide or minimize/restore the owner form, the owned form goes along with it. In fact you can have a whole stack of owned forms.

    The ownership idea seems rather neglected but it's not there for nothing. Besides the Form.Owner and Form.OwnedForms properties, the framework provides Form.AddOwnForm and Form.RemoveOwnedForm methods. An MSDN search with the search string "owned form" (including the quotation marks) yields 72 hits. Without the quotation marks, it yields more than 200,000 hits. That might be interesting reading for someone who can't think of a use. Or see the Slide Show link in my signature below for an example.

    BB

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Child form in front of the controls on parent form

    Quote Originally Posted by boops boops View Post
    The the "Me" in form1.Show(Me) is a simple way to make it the Owner of form1.

    The owned form is locked in front of the owner (and its child controls) in the Z order, so no other form can come between them. If you close, show/hide or minimize/restore the owner form, the owned form goes along with it. In fact you can have a whole stack of owned forms.

    The ownership idea seems rather neglected but it's not there for nothing. Besides the Form.Owner and Form.OwnedForms properties, the framework provides Form.AddOwnForm and Form.RemoveOwnedForm methods. An MSDN search with the search string "owned form" (including the quotation marks) yields 72 hits. Without the quotation marks, it yields more than 200,000 hits. That might be interesting reading for someone who can't think of a use. Or see the Slide Show link in my signature below for an example.

    BB
    "Owned form" is basically .NET parlance for a modeless dialogue. A perfect example of the concept of an owned form is the Find & Replace dialogue in VS. I think that any tool windows behave the same way when they're not docked, but I'm not 100% sure of that.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width