Hidden modal form is not included in My.Application.OpenForms

G

ginacresse

I am trying to close/dispose multiple instances of a form but because they
are modal and hidden, they do not show up in My.Application.OpenForms. They
must be modal, so making them modeless is not an option. I also need to
check the values in a spread control on the forms before I close/dispose
them. I'm using VB 2005. Is there some way for me to do this?
 
A

Armin Zingler

ginacresse said:
I am trying to close/dispose multiple instances of a form but
because they are modal and hidden, they do not show up in
My.Application.OpenForms.

Hidden Forms can not be modal. If you hide them, ShowDialog returns.
Consequently they are not in a modal state anymore.

They must be modal, so making them
modeless is not an option. I also need to check the values in a
spread control on the forms before I close/dispose them.

Close and Dispose are different things with modal Forms. You can close
the Form, then access the spread control on the Form, then Dispose the
Form.
Only with modeless Forms, closing also means disposing. Just for the
purpose you mentioned that's different with modal Forms.
I'm using
VB 2005. Is there some way for me to do this?

Other than accessing the spread control?

Is there a reason why you mentioned My.Application.OpenForms? If you
have shown several instances of a modal Form, there must be one on top
of the other. Otherwise you'd have to create multiple UI threads.
However, if they are all hidden, there must be any Form left over,
right? Could you please give a picture of your UI infrastructure (which
Form shows which one, and how (modal/modeless)? MDI Form available?
Project's startup object is a Form? Are there owner-child relations)?


Armin
 
G

ginacresse

I hope this doesn't get posted twice, but I tried to reply once and it never
showed up.
The forms are structured as follows:
The startup form is an MDI form. The user can Show a child form (Form1)
from the MDI form. Form1 has a context menu item that, when clicked, creates
a new instance of Form2 with ShowDialog() (I assume this means Form2 is
Modal, which is why I use the term). Form2 has Button1 and Button2. If the
user clicks Button1, a new instance of Form3 is created and shown with
ShowDialog(). When the user is done with Form3, it gets hidden with
me.hide(). The user can keep coming back to Form3 (generated with Button1)
and the data on the form will still be there. The user can also click
Button2 and create another instance of Form3 (specifically created with
Button2) and ShowDialog(), then hide it when done. There may be other
instances of Form3 open/hidden in the application, but when the user closes
Form2, I want to Dispose the instances of Form3 that were created with
Button1 and Button2. The reason I wanted to be able to check the spread
control on Form3 was to somehow determine if it is a form I want to dispose,
but there is probably a better way. I’ve been reading about OwnedForms and
maybe that is the route I should take? Anyhow, any help is appreciated.
Thanks.
 
A

Armin Zingler

Thx for the detailled description. I'll have a look when I'm awake (the
real being awake).

AZ
 
G

ginacresse

I ended up solving the problem another way. When I create each new instance
of Form3, I add it to the list of OwnedForms for Form2. When I close Form2,
I loop through Form2.OwnedForms and dispose them. Works great.

Thanks.

Gina
 

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

Top