vb.net mdi parent hides when another form opens - vb.net

I have a program written in vb.net. It has a mdi parent form as the main form and several child forms. I also have dozens of forms that are not child forms and when I use showdialog() the mainform(MDI parent) hides behind other open applications until the the new form(not child form) finishes opening. I tried showdialog(me) and it doesn't work. I can't use just form.show(me). I searched for hours and can't find a fix. Any help would be greatly appreciated.
form2.TopMost = True
form2.WindowState = FormWindowState.Normal
form2.ShowDialog(Me)
this code is called from toolstripmenu from the mainform

Related

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)

vb.net Prevent Form 1 from activating when form 2 is clicked

im having a similar problem like the solution here Prevent main form from appearing when showing another form . but some of the suggestions were to minimize the main app so it doesnt show, which i cant do because my main app is supposed to be a desktop to be underneath all other apps to replace the windows desktop. And the second forms are supposed to be sticky notes. so i cant minimize the main window cause it has the user background and other controls. i tried making the parent of the notes a Nothing pointer, a pointer to the desktop, creating the form through a dll but i had no success.
My main problem is that when i click a note (form2) form1 comes up, even with form1 having the WS_EX_NOACTIVATE in the createparams. form1 does the form2.show() but they shouldn't be attached.
Another reason im having trouble with the solutions preseted in that post is that they are for delphi and im doing it in vb.net.
All i need is being able to click on the controls and write in the note without bringing the main form behind the note. either making them independent, or making the note not focusing the first form or being able to operate the note without it activating. i dont know. my last resource is to attach my main form to the desktop but i've heard is the worst thing you can do because it can cause problems hanging the system.
If you want both forms to co-exist but don't each to interfere with the other: In this case, then you might want to have a third Form that calls both Form1 and Form2 to be opened, and let me suggest and MDI Form with Form1 and Form2 as children forms of the MDI form
'============== my previous post ========================
You can force the user to first dismiss Form2 then allow him to go back to form1 by showing Form2 as Modal form. Here is how to display Form2 as modal
Dim f2 as New Form2
f2.ShowModal()
If that does not work, try this
Dim f2 as New Form2
f2.Show(True)