473,326 Members | 2,680 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,326 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 10713
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.