tags:

views:

48

answers:

4

I have a project with multiple forms and when, for example, Form A opens Form B which opens Form C, then Form C is closed, Form B and Form A have gone to the back of the window order, so that whatever other programs are open are shown in front of these other forms in the project.

Why is this happening and how would I go about making sure the last opened form is shown when another form is closed?

+1  A: 

You could track the "last" form in each of your forms, and on close, activate it. ie: if Form B opens Form C, Form C could keep a reference to Form B (or any form to activate on close), and force it to the foreground when you close your form.

That being said, I personally think that it's often better to just let the operating system perform its normal window manipulation/handling, unless there is a specific reason to override it. Applications that force their windows into the forefront often annoy me - instead of being beneficial, it can be disruptive to your users.

Reed Copsey
It isn't that I want to disrupt the flow, it is that my program itself is the one being disrupted. Upon closing Form C, the topmost form should be the one that opened it, Form B. Even if another program was /not/ brought up between the two, other programs are bought to the front above Form B when Form C is closed.
Totty
Then the first paragraph I wrote should work fine for you - just activate the other form when you close/hide the one in front. This can be a single Form property, that, if it's not null, you activate.
Reed Copsey
There's already a mechanism for accomplishing this, though, in the Form's Owner property.
Adam Robinson
A: 

You could have a series of Dialog forms opened from a single form, in order. What this allows you to do is check the DialogResult - you'd then be able to control the direction in which you open new forms or show old forms.

If you're worried about the z-order of so many forms, you might consider changing your UI to avoid multiple non-modal windows.

Charlie Salts
+2  A: 

Ensure that you are setting the Owner property of forms that are opened by other controls or Forms, either by setting the property explicitly or by passing the owner in as a parameter to Show() or ShowDialog().

Adam Robinson
A: 

Well maybe you need to set up the new forms as a modal dialog with the ownership to the older forms. This way when the new form closes the new form will be visible. Additionally as long as the new form is open, nobody will be able to access the older forms.

Cyril Gupta