473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Is MDI child open or not?

I'm trying to detect if a given mdi child is open in my app using the
following code in the main form (if it is open, I want to view it, not
create a new instance):
Public Function isOpen(ByVal frmName As String) As Boolean
Dim i As Int16
isOpen = False
For i = 0 To Me.MdiChildren.Length - 1
If DirectCast(Me.MdiChildren(i), Form).Name = frmName Then
isOpen = True
End If
Next
end

The problem is, this seems to detect the existence of dead forms.

Is there a way to do what I want?
Jan 17 '06 #1
4 1340
what do you mean by "dead form". as far as i know, whenever you unload
or dispose the child form, mdi form leaves the reference of that form
so how come you are getting such references?
it shouldnt happen at all.

check out your code again

Lucky

Jan 17 '06 #2
"JeremyGrand" <je****@ninprodata.com> schrieb:
I'm trying to detect if a given mdi child is open in my app using the
following code in the main form (if it is open, I want to view it, not
create a new instance):


\\\
Private m_Child As Form2

Private Sub Button1_Click( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles Button1.Click
If m_Child Is Nothing Then
m_Child = New Form2()
m_Child .MdiParent = Me
AddHandler m_Child.Load, AddressOf Me.MdiChild_Load
AddHandler m_Child.Closed, AddressOf Me.MdiChild_Closed
m_Child.Show()
Else
m_Child.Activate()
End If
End Sub

Private Sub MdiChild_Load( _
ByVal sender As Object, _
ByVal e As EventArgs _
)
MsgBox( _
"MDI child with handle " & _
DirectCast(sender, Form).Handle.ToString() & _
" loaded!" _
)
End Sub

Private Sub MdiChild_Closed( _
ByVal sender As Object, _
ByVal e As EventArgs _
)
MsgBox( _
"MDI child with handle " & _
DirectCast(sender, Form).Handle.ToString() & _
" closed!" _
)
m_Child = Nothing
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jan 17 '06 #3
Herfried, thanks for pointing me in the right direction. The FormClosed
event is exactly what I was looking for.

I prefer to put code related to a form in the form itself and I have a
custom session singleton, so my implementation is a little different than
your suggestion:

Public Class frmMyForm
Inherits System.Windows.Forms.Form
Shared frm As frmMyForm= Nothing
....
Public Shared Sub Execute(ByRef MySession as ..)
If frmMyForm.frm Is Nothing Then
frm = New frmMyForm
With frm
.MdiParent = MySession.MDIParent
....
end with
end if
frm.Show()
end sub
....
Private Sub frmMyForm_FormClosed(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
frm = Nothing
End Sub

Jeremy
Jan 17 '06 #4
I wrote these two small procedures to start a form. Works perfectly and
prevents double instances

' This is the procedure to call to open a form
Private Sub OpenView(ByVal FormName As String)
If My.Application.OpenForms(FormName) Is Nothing Then
ShowFormByName(FormName)
Else
My.Application.OpenForms(FormName).Activate()
End If
End Sub

' This is an underlaying sub, called from the one above
Private Sub ShowFormByName(ByVal FormName As String)
Dim ThisForm As Form
Dim ThisType As Type
ThisType = Type.GetType("appEspital." & FormName)
ThisForm = DirectCast(Activator.CreateInstance(ThisType), Form)
ThisForm.MdiParent = Me
ThisForm.Show()
End Sub


"JeremyGrand" <je****@ninprodata.com> wrote in message
news:e4**************@TK2MSFTNGP14.phx.gbl...
I'm trying to detect if a given mdi child is open in my app using the
following code in the main form (if it is open, I want to view it, not
create a new instance):
Public Function isOpen(ByVal frmName As String) As Boolean
Dim i As Int16
isOpen = False
For i = 0 To Me.MdiChildren.Length - 1
If DirectCast(Me.MdiChildren(i), Form).Name = frmName Then
isOpen = True
End If
Next
end

The problem is, this seems to detect the existence of dead forms.

Is there a way to do what I want?

Jan 31 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: H2 | last post by:
Hi all, Any one know how to open a new windows in a child window using javascript? What I need to do is that, in my main page, there is a button, onclick, it opens one child windows. In the child...
1
by: ian.michel | last post by:
I have a parent window that pushes a new window object onto an Array with the following code : OpenChild() { //totalNumWindowsCreated is global totalNumWindowsCreated =...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
2
by: Paul | last post by:
Hi this is related to a previous post, hopefully just a bit clearer description o the problem. I have a parent form that opens a new form (child form) while still leaving the parent form open....
2
by: QT | last post by:
Dear Sirs, I made a MDI Parent form and two MDI child form. I can open MDI child form from MDI parent form with; Dim UserChangePassword_Form As New UserChangePassword 'Set the Parent Form of...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
14
by: Simon Abolnar | last post by:
I would like to know how to open child form from dialog form. Thanks for help! Simon
1
by: Filip Vanderstappen | last post by:
Hello, I think a lot of people already asked my question! I'm learning vb.net and now I have a MDI-parent with one child. Everytime I press a button to open the child it will open a new form. I...
13
by: Academic | last post by:
I have a MDI form, sometimes child forms and sometimes forms that are neither If I close the app the child forms closing and closed event happens followed by the Mdi form receiving the...
4
by: Buddha | last post by:
Hello, I posted this on two forums, without too much help .. and I am kinda stuck in this. I need to refresh the parent page from the second child window which is opened by the first child and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.