VB.NET Difference between Focus() and BringToFront() - vb.net

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)

Related

Make an MDI child form no longer a child

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

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.

vb.net using SetParent API over IsMDIContainer?

I'm working with a set of custom controls (including a custom form), I have repainted the custom form to give it a metro style look and basically recreated the title bar of the form. Setting this form to be an MDI container causes the whole form to be repainted grey regardless of anything dictated in the OnPaint handler for the form.
I want to create a multi form application where all of the forms that are not the main form, appear inside the main form (the idea of MDI windows). I have also seen a SetParent API that achieves a similar effect without modifying its visuals, however, I have used this before to tie a cmd window to a form and it is not always reliable.
Would it be more efficient to use the MDI feature inside Winforms (if so, how do i overcome the complete recolour issue) or dump MDI and use the SetParent API to modify the child windows' parent?
EDIT: I have decided to go for using the SetParent API, it works everytime as opposed to my previous experiences with the console window. However, I need to create the window before I can set the parent and sometimes the user can see the screen flash briefly before it gets 'hooked' inside my main form. Is there a way to 'hook' it without it being visible to the user?
With MDI Parent Form if your issue is the background, then this is all you have to do, Set the IsMDIContainer property of the form to true, and then loop through each control on MDI Form to let them know this is the MDI Background, you can put this code in the form loading event,
Private Sub FormMDI_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each ctl As Control In Me.Controls
If TypeOf ctl Is MdiClient Then
ctl.BackColor = Me.BackColor
End If
Next ctl
End Sub
It might appear gray when program is not running, but it will show your desired background once the program runs

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