Closing forms opened with show when parent form closes

R

RD

Dim myfrm as new frmb
myfrm.show()

Dim myfrm2 as new frmc
myfrm2.show

Opens two forms from a butom located on forma

when I close forma I would like both form myfrm and for myfrm2 to close
automatically

Can anyone tell me how or point me to some sample code that does this type
of thing?

Thank you for any help

Bob
 
A

Armin Zingler

RD said:
Dim myfrm as new frmb
myfrm.show()

Dim myfrm2 as new frmc
myfrm2.show

Opens two forms from a butom located on forma

when I close forma I would like both form myfrm and for myfrm2 to
close automatically

Can anyone tell me how or point me to some sample code that does this
type of thing?

Form A has a closed event. Handle the event (or overwrite OnClosed) and
close the other forms by calling their Close methods.

You can also make form A the owner of the other forms, so they be will
automatically closed when form A is closed, but the owned forms (B and C)
will always be in front of the owner form (A). In addition, the owned forms
will automatically be minimized when the owner form is minimized. The might
be useful - but if you don't want this behavior you can go the first way.
 
R

RD

Thanks Armin,
But that is exactly what I can't figure out how to do.

The Dim for the myFrm as new frmb is in thebutton_click event so the
instance that is open (myfrm) can not be referenced directly from within the
formA's closed event. It is out of scope because Myfrm is private to the
button_click event. So how do you refer to it in the code in the closed
event?


To refer or not to refer, that is the question ;-)

Bob
 
A

Armin Zingler

RD said:
Thanks Armin,
But that is exactly what I can't figure out how to do.

The Dim for the myFrm as new frmb is in thebutton_click event so
the instance that is open (myfrm) can not be referenced directly from
within the formA's closed event. It is out of scope because Myfrm is
private to the button_click event. So how do you refer to it in the
code in the closed event?


To refer or not to refer, that is the question ;-)

Declare the variables at class level (= as fields of the class; named
"Module Scope" in the following chapter):

http://msdn.microsoft.com/library/en-us/vbcn7/html/vbconScopeLevels.asp



see also:
http://msdn.microsoft.com/library/en-us/vbcn7/html/vbconAddingPropertiesMethodsToClass.asp
http://msdn.microsoft.com/library/en-us/vbls7/html/vblrfVBSpec7_5.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top