Bug in Forms Collection?

G

Guest

I am writing an application in which the user can toggle the layout style
from MDI to SDI. I started off using the OpenForms collection to track the
forms the application has open but have come across a bit of a bug (I think).
If you hide a change a forms visible property to false i.e. hide it, it
seems to drop out of the OpenForms collection. Is this supposed to happen?
 
S

Stoitcho Goutsev \(100\)

nbk,

My test show that simply hifing a form doesn't remove the form the OpenForms
collection.

I looked in the Form class wth the reflector and I can see that forms are
removed from this collection in response to the FormClosed event. This event
in .NET 2.0 replaces the Closed event form the previous versions. As long as
setting Visible to false or calling the Hide method doesn't fire this event
the form shouldn't be removed from the collection. That is exactly what my
test show.

Can you repro the issue your are having in a small compilable test
application?
 
G

Guest

Hi Stoitcho,

I have knocked up a very quick example as you requested to illustrate my
point. You can download it from

http://development.gnitouch.com/openforms.zip

Steps to reproduce behaviour

1. Start the application
2. Select File | New Window from the menu (brings up a new Mdi child window)
3. Select File | Window Count (displays 2 as expected)
4. Repeat step 2
5. Repeat step 3 (displays 3 as expected)
6. Press the Hide button on any of the Mdi child forms (the form disappears
i.e. is hidden)
7. Select File | Window Count (displays 2??? why is my hidden form not
included)

Hope you can clear the confusion :)
Cheers
nbk
 
S

Stoitcho Goutsev \(100\)

nbk,

I actually didn't test this with MDI child forms. In this case the removing
happens in other place and this is in response to HandleDestroyed event. In
its SetVisibleCore override the Form class checks if the form is MDI Child
and if it is it destroys the handle to the underlying native window, thus
the form gets removed. Why the do this? Frankly I don't know but I suspect
that if they don't do this the native support for MDI windows that I believe
they use under the hood will not working correctly.



Anyways if you are interested in the number of MDI child forms regardless of
their visible state I'd suggest checking the Form.MdiChildren.Length. It
returns correct number of the mdi children including the hidden ones
 
G

Guest

Goutsev,

Unfortunately in my case the user's requirements are such that they need to
have both MDI and SDI capability, the MdiChildren scenario will only work
when they have "docked" the forms (i.e. they are in MDI Mode). If they choose
the SDI option the MdiChildren property becomes useless to me.

Looks like I will have to track the forms (when they open and close). This
is something I was hoping to avoid but it looks like I have no choice :(

BTW Thanks for taking the time to reply
 

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