Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2007

Tip: Looking for answers? Try searching our database.

Openforms collection in 1.1 .NetFrameWork??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WhiskeyRomeo - 05 Jul 2007 18:56 GMT
There appears to be no openforms collections in 1.1 version on the
.NetFramework.  

How do I iterate through and close all opened child forms in a Window MDI
application? (In VB.Net although I can usually make out C# code)

WR
Kevin S Gallagher - 05 Jul 2007 19:20 GMT
Here something I used in 1.1 so I am guessing you could close a form using
this logic

  Function IsFormLoaded(ByVal ToBeLoadedForm As String) As Boolean
     Dim LoadedForm As Form

     Try
        For Each LoadedForm In Me.MdiChildren
           If LoadedForm.Name = ToBeLoadedForm Then
              Return True
              Exit For
           End If
        Next
     Catch ex As Exception
        MsgBox(ex.Message & vbCrLf & ex.Source & vbCrLf & ex.StackTrace,
MsgBoxStyle.Critical, "Error")
     End Try
     LoadedForm = Nothing
  End Function

> There appears to be no openforms collections in 1.1 version on the
> .NetFramework.
[quoted text clipped - 3 lines]
>
> WR
WhiskeyRomeo - 05 Jul 2007 19:54 GMT
Thanks for the reply.  I am pretty sure you cannot modify the collection
while iterate over it using the for each statement.  But you gave this idea
which works.

       Dim myforms() As Form = Me.MdiChildren
       Dim i As Int16
       For i = (myforms.Length - 1) To 0 Step -1
           myforms(i).Close()
       Next

So it appears that MdiChildren is array of open forms.

Bill

> Here something I used in 1.1 so I am guessing you could close a form using
> this logic
[quoted text clipped - 23 lines]
> >
> > WR
Kevin S Gallagher - 06 Jul 2007 15:33 GMT
Bill,

Glad to help...Your code is exactly what I was moving you towards :-)

Kevin

> Thanks for the reply.  I am pretty sure you cannot modify the collection
> while iterate over it using the for each statement.  But you gave this
[quoted text clipped - 40 lines]
>> >
>> > WR
John - 09 Jul 2007 18:06 GMT
For Each frm As Form In Me.MdiChildren
  frm.Close()
Next

J

> There appears to be no openforms collections in 1.1 version on the
> .NetFramework.
[quoted text clipped - 3 lines]
>
> WR
WhiskeyRomeo - 09 Jul 2007 18:22 GMT
I haven't tried this; but, again, I believe you cannot delete members of a
collection while iterating over it with the for-each statement.  That is why
I chose the other solution I posted.

> For Each frm As Form In Me.MdiChildren
>    frm.Close()
[quoted text clipped - 9 lines]
> >
> > WR
John - 10 Jul 2007 11:34 GMT
Hi,

The sample I gave you works fine.

It is interesting your point regarding whether or not you can
delete members of a collection while iterating over it with a
for each, I don't have a definative answer for that.  Regardless,
that is not what is occurring in this case.

My code does the same thing as yours but is more concise and
more importantly the variables go out of scope after the for
next, thus helping to avoid a memory leak.

The key point here is that MdiChildren returns a new array.  In
your code you are working against the array returned by
MdiChildren just like I am.  Perhaps what you intended to do
was this:

Dim myforms() As Form
Me.MdiChildren.CopyTo(myforms, 0)
Dim i As Int16
For i = (myforms.Length - 1) To 0 Step -1
  myforms(i).Close()
Next

The above is redundant because MdiChildren is already
making a copy of the internal array.  Does that make sense or
is my understanding incorrect/incomplete?

Thanks.

J

>I haven't tried this; but, again, I believe you cannot delete members of a
> collection while iterating over it with the for-each statement.  That is
> why
> I chose the other solution I posted.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.