473,396 Members | 2,081 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,396 software developers and data experts.

How can i loop through mdi child forms? Code please

Hi Everyone,

in vb6 i was able to execute the following code and it would close the
children is the reverse order they were opened eg the last child
opened was the first child to close.

in mdiparent i had this code

i = Forms.Count - 1
Do Until i = 0
If Forms(i).Name <> "mdiMain" Then Unload(Forms(i))
i = i - 1
Loop

in the queryunload event of each child form i would prompt the user
if msgbox(msg) = vbyes then
'clean up objects etc
else
cancel = true
end if

setting cancel to true, seemed to kill the loop in the code in
mdiParent.

i have tried using in the new vbnet mdiParent form:

Dim f As Form
For Each f In Me.MdiChildren
if Not IsNothing(f) Then f.Close()

'somehow capture if the user has
'cancelled the close of a child form and exit loop

Next

in the closing event of each child
if msgbox(msg) = vbyes then
'clean up objects etc
else
e.cancel = true
end if

the forms seem to close in the order they are opened, however i would
prefer them to close in reverse order.

also, how can i capture if a user has canceled the form close event?
is there something already existing that i can check, i am not a fan
of setting global flags.

ideally, i would like the vb.net code equivalent of my old vb6 code

many thanks

Edwinah63
Nov 21 '05 #1
8 10722
Edwinah,

What is that sentence "clean up objects", when you have done everything as
it should be, than that is done by the framework. That is one of the reasons
why it is managed code.

Maybe this helps already something?

Cor
Nov 21 '05 #2
Hi,

Try something like this.

Dim f() As Form = Me.MdiChildren

For x As Integer = f.GetUpperBound(0) To 0 Step -1

f(x).Close()

Next

Ken

-------------------

"Edwinah63" <ed*****@customercare.com.au> wrote in message
news:d7**************************@posting.google.c om...
Hi Everyone,

in vb6 i was able to execute the following code and it would close the
children is the reverse order they were opened eg the last child
opened was the first child to close.

in mdiparent i had this code

i = Forms.Count - 1
Do Until i = 0
If Forms(i).Name <> "mdiMain" Then Unload(Forms(i))
i = i - 1
Loop

in the queryunload event of each child form i would prompt the user
if msgbox(msg) = vbyes then
'clean up objects etc
else
cancel = true
end if

setting cancel to true, seemed to kill the loop in the code in
mdiParent.

i have tried using in the new vbnet mdiParent form:

Dim f As Form
For Each f In Me.MdiChildren
if Not IsNothing(f) Then f.Close()

'somehow capture if the user has
'cancelled the close of a child form and exit loop

Next

in the closing event of each child
if msgbox(msg) = vbyes then
'clean up objects etc
else
e.cancel = true
end if

the forms seem to close in the order they are opened, however i would
prefer them to close in reverse order.

also, how can i capture if a user has canceled the form close event?
is there something already existing that i can check, i am not a fan
of setting global flags.

ideally, i would like the vb.net code equivalent of my old vb6 code

many thanks

Edwinah63
Nov 21 '05 #3
> What is that sentence "clean up objects"

sorry Cor, this is just my own user made objects, not system objects
etc i prefer to explicitly extinguish user made objects rather than
relying on them to just go out of scope.

However, does anyone know how i can capture if the user has cancelled
the close of a child form?

all thoughts appreciated. many thanks to Ken for his code.

Edwinah63
Nov 21 '05 #4
Edwinah,

It should not be necassary however maybe you can use this.

\\\
For Each frm As Form In Me.MdiChildren
' do cleanup
Next
///

I hope this helps?

Cor

">
sorry Cor, this is just my own user made objects, not system objects
etc i prefer to explicitly extinguish user made objects rather than
relying on them to just go out of scope.

However, does anyone know how i can capture if the user has cancelled
the close of a child form?

all thoughts appreciated. many thanks to Ken for his code.

Edwinah63

Nov 21 '05 #5
Does anyone know how to capture if a user has cancelled the close event on a form?

i am not sure that question was answered.

ta
Nov 21 '05 #6
Did you see my answer?

When a form is in that loop it is not closed.

Cor
Nov 21 '05 #7
"Cor Ligthert" <no**********@planet.nl> wrote in message news:<uO*************@TK2MSFTNGP12.phx.gbl>...
Did you see my answer?

When a form is in that loop it is not closed.

Cor


Hi Cor,

i did see your answer:

For Each frm As Form In Me.MdiChildren
' do cleanup
Next

but i am not sure it is applicable here.
i am currently using Ken's code in my app:

Dim f() As Form = Me.MdiChildren

For x As Integer = f.GetUpperBound(0) To 0 Step -1

f(x).Close()

Next
What i am after is a way of stopping the loop if a user cancels an
explicit close eg:

Dim f() As Form = Me.MdiChildren

For x As Integer = f.GetUpperBound(0) To 0 Step -1

f(x).Close()

if UserCancelsChildFormClose then
'exit for or do something else
end if

Next

i can achieve this by setting a global varible but i was wondering if
there is something native in the forms that i can detect (a cancel
event???).

many thanks

Edwinah63
Nov 21 '05 #8
Edwinah,

In every close event from a form is the e.cancel, you can set that to true
or false and I am never sure if it is e.cancel = true means cancel the close
operation or that it means e.cancel is true close the class, so try it
yourself. (I thought it was the first)

Than you can check in that close event if it is done in the correct way or
that the user has pushed the close X in the top.

To get the main form in a mdichild is
me.parent.xxxxx

I hope this helps?

Cor
Nov 21 '05 #9

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

Similar topics

8
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender,...
3
by: James Spibey | last post by:
Hi, I have an MDI application which has aboout 10 child windows. The way the app needs to work is that only one window should be visible at a time and it should be maximized within the parent...
3
by: Maheshkumar.R | last post by:
Hi groups, How i can command over the MDI CHIlD forms created dynamically at runtime from PARENT. Let say, i have generated 5 mdichild forms, but i want to work with child form1 from MDI...
1
by: Tim | last post by:
Hi, I'm very new to .NET and am programming in C#. I have a web application where i have two list boxes. Its kind of like a shopping card where you can add items from one 'locations' list box to...
3
by: Lance | last post by:
I've noticed that controls that are contained in MDI child forms fail to raise MouseLeave events if the MDI child form's MdiParent property is set to Nothing (after it was set to an existing MDI...
0
by: Bruin | last post by:
Hi All, I'm having a problem with MDI child forms when the reference to the MDI Parent is set in a Control library. (Sorry for the long post) I have an control library assembly which holds all...
7
by: Siv | last post by:
Hi, I have an MDI application that uses a generic "ShowPage" routine in a module that is called when I want to display a child form. The basic idea is that in the module I have declared each form...
2
by: Lenster | last post by:
Environment --------------- Visual Studio.NET 2003 Version 7.1.3088 ..NET Framework 1.1 Version 1.1.4322 SP1 XP Professional 5.1.2600 SP2 Build 2600 Problem Description...
5
by: Earl | last post by:
I need to call a method on an owned child form, and am wondering if the best way of doing this is to capture the Closing event of the form that passes control back to the form where I have the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...

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.