Make an MDI child form no longer a child - vb.net

Using VB.Net:
Is there a way to make a child form that is inside an MDI parent form no longer a child form? For example, I have an entryForm.vb inside of mainForm.vb. On double click (or other event) I want entryForm.vb to be fully sizable and outside of the mainForm.vb without losing text.
I have tried changing the MDI settings of entryForm.vb but that does not seem to work.

Set the property MDIParent of the form instance to Nothing

Related

Opening Mdi Parent as an Object won't let open Mdi Child form from another Mdi Child Form in VB.Net

I got a weird problem with MDI Parent form.
I open forms like -> Login Form(is not a MdiContainer) -> MdiParent (Is a MdiContainer).
But I wanted to pass a boolean value from Login Form to MdiParent Form so I declared a Friend variable in MdiParent Form and called MdiParent Object in Login Form as shown in below code.
Dim frm As New MdiParent
'frm.NormalMode = True
frm.Show()
Everything works fine. MDIParent form opened as expected.
But I have some child form in MdiParent form.
A child Form has a button which does is open another child form with Parent MDIParent shown below.
Dim frm1 As New Child2
frm1.MdiParent = MdiParent
frm1.anyvariable = value
frm1.Show()
But now it won't open. Like on button click it comes to the breakpoint passes through frm1.show() command line but it won't open.
Before I was Opening MDIParent directly like MdiParent.show() and everything worked fine.
All child Forms opened properly with this code.
Something Extra:
Also, When I run with MdiParent.Show() and Pause the code in VS2017 and uncomment the MDIParent code with Object (the one above) and comment MdiParent.Show() It works fine. Again, stopping and replaying the code creates issues.
Also, I didn't use that Boolean variable in MdiParent Form yet so it's not a problem I guess.
Using a Public variable is a convenient way, for now, I guess.
Also declaring Friend variables between two child forms is not an issue at all.
I think what's happening is that, in this line:
frm1.MdiParent = MdiParent
the part on the right is being interpreted as being the default instance of the MdiParent class rather than the MdiParent property of the current form. As a result, the new form is being parented by that default instance, which you haven't displayed, rather than the instance that you explicitly created and did display. That would also explain why it works when you use this:
MdiParent.Show()
which is displaying the default instance. The fix is easy. You just need to qualify the name to indicate that it is actually the property of the current form that you're referring to:
frm1.MdiParent = Me.MdiParent
Alternatively, use a better name for your form than MdiParent, like MainForm or the like. Then there will be no name clash.

Cant unhide all child forms? vb.net

I have the flowing problem. I have a vb.net parent form with MDI children that contain sensitive information. I have made a pause button which should hide all child forms from sight, this is no problem, calling them back is. i have for testing purposes created a button which should do the reverse however all my child forms stay hidden can somebody assist?
Code to hide all child forms is as follows:
For Each frmApproval As Form In Me.MdiChildren
frmApproval.Visible = False
Next
System_Paused.MdiParent = Me
System_Paused.Show()
Now the form nammed System_Paused has a button on it which when clicked should revert the hidden child forms but its not working?
For Each frmApproval As Form In Me.MdiChildren
frmApproval.Visible= true
Next
Me.Close()
You're iterating over the wrong MdiChildren collection.
You hide the children of your main form, but then you try to set the visibility of the children of the System_Paused form.
You could solve this issue by using something like this:
For Each frmApproval As Form In Me.MdiParent.MdiChildren
frmApproval.Visible = true
Next
since you already set your main form as MdiParent of the System_Paused form.

In VB.NET LostFocus is not working on my MDI child container

If I set up two forms, I can close one or the other by using the ".Close()" function on the form's handle. However, this does not work on Mdi Forms. The child form never seems to lose focus by clicking on any other child or the parent since the forms are all children of the parent. As long as the parent has focus, then children also have focus.
Is there a way to determine if the child form has lost focus and if so close it?
I use this for my regular (non-Mdi) forms and it works great:
AddHandler sub_menu.LostFocus, AddressOf close_menu
Thanks.
When a form gets the focus, close all the MDI child forms that are not the ActiveMDIChild of the parent form.

how to know my application lost focus in VB.NET

I am using VB.NET to build my application. And in my application has a lot of Forms. It doesn't use MDI Parent Form, but I use another simple Window Form (I named it frmMain) that I suppose it is my MDI Parent Form. When frmMain load, windowState = Maximized. And when I open a Form (example: I named it frmCustomer) that I suppose it is my child Form, and I set its properties (frmCustomer.TopMost=True) when it load, so it always on the top. But When I change to open another application such as Ms. Word or Mozilla Firefox... the frmCustomer is still on the top. My question is that; how can I know my frmMain lost focus?
If you want the form to stay in front of the main form, but not other applications, the simpler solution would be to set the main form as the child form's owner. For instance:
childForm.Show(parentForm)
or
childForm.Owner = parentForm

VB.NET Difference between Focus() and BringToFront()

I'm developing an application in WinForms and I have 2 MDI children and I'd like to know the difference between Form.Focus and Form.BringToFront
I would like to know which one to use when clicking on a respective form's titlebar in order to have it pop up while I'm drag/dropping the form
If you are setting the child form mdiParent property after you are calling Form.Show then it messes up the focus of all the child forms so for me, drag/drop of MDI children inside an MDI parent won't focus the form upon Drag start, but only after MouseUp
Focus() sets focus to U element.
BringToFront() brings your element on top of other elements (which overlap your element).
So if you use BringToFront() on your form, it will be brought to front over over windows in your MDI environment. But it doesn't mean that your form will gain focus.
If you use Focus(), your form will gain focus: for example you will be able to interact with the form via keyboard. But it does not mean that form will be brought to front over other forms.
So maybe you should use both methods.
When I open MDI Child Forms, I create the following function within the MDI Parent:
Public Sub ShowMDIChild(f As Form)
f.MdiParent = Me
f.Show()
End Sub
The "f" argument is the new form I wish to open:
MyMDIPParent.ShowMDIChild(New Hospitals)