-
Feb 9th, 2022, 10:45 AM
#1
Thread Starter
New Member
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!
-
Feb 9th, 2022, 02:51 PM
#2
Re: Child form in front of the controls on parent form
Leave out the MDIParent and TopMost statements, and add 2 letters to the remaining line:
BB
-
Feb 9th, 2022, 05:15 PM
#3
Thread Starter
New Member
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.
-
Feb 9th, 2022, 08:29 PM
#4
Re: Child form in front of the controls on parent form
Originally Posted by Anderskd1
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.
-
Feb 10th, 2022, 07:44 PM
#5
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?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 12th, 2022, 07:03 AM
#6
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
Last edited by boops boops; Feb 12th, 2022 at 07:10 AM.
-
Feb 12th, 2022, 08:31 PM
#7
Re: Child form in front of the controls on parent form
Originally Posted by boops boops
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|