How to get in front MDI child form?

B

Billy

Hello!

I have a main form as MDIContainer in VB.NET 2002 App. Form has menu
which call several forms. I call forms that way:
--
Dim f As New frmNameX()
LoadForm(f)
--

Procedure LoadForm check if form is already loaded.

Private Sub LoadForm(ByVal frmName As Form)
If Not IsLoaded(frmName) Then
MyForms.Add(frmName) 'Add form to collection list
frmName.MdiParent = Me
frmName.Show() 'Display form on screen
Else
'Bring already open form in focus before other forms
'???? How
End If
End Sub

IsLoaded is function which return True if is loaded and False if it
isn't.

I have more then 20 forms so has to be checked all through one
procedure without defining each forms as separate variable and then
reference on that variable.

I tryed all combinations I know with Activate, Focus, TopLevel, TopMost
etc. without success.
I also have in menu "Window" (set as MDIList=True) where I select
already open form and that work fine. I would like to have the same way
if user would select in my menu same form again.

I think I missed one important step, but don't know which one. Can
anybody help me with that problem?

Regards,
Billy
 
G

Guest

Hi Billy

I don't think you need the separate collection - the MdiChildren of the
parent MDI form should do the trick. try this:

Private Sub LoadForm(ByVal f As Form)
For Each currentForm As Form In Me.MdiChildren
If f.GetType Is currentForm.GetType Then
currentForm.Activate()
Return
End If
Next
f.MdiParent = Me
f.Show()
End Sub

That works for me...

HTH

Nigel Armstrong
 
B

Billy

Thank you Nigel!

It's working exactly what I tryed to achieve. Could be some similar
loop also possible for non MDI forms?

For example in my previous code I could comment out line
"frmName.MdiParent = Me" and forms open outside the main window but
only once (no duplicates). But I couldn't activate on any way already
opened form nor in MDI option nor in non MDI (outside the main
window).

Regards,
Billy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top