By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,281 Members | 2,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,281 IT Pros & Developers. It's quick & easy.

How to get in front MDI child form?

P: n/a
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

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"Billy" wrote:
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

Nov 21 '05 #2

P: n/a
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
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.