Child form focus problem

C

Christer

Hi all,

An application I am woking on consist of a main form. On the main form
there are several possible ways for the user to open a non-modal child
forms to display even more information.

The problem I am encountering is about loss of focus. Let's say here,
that initialization of the child form takes about ½ second, from the
point where the window is first shown to the point where all controls
have been rendered and set with data.

Now, on the main form there is a datagridview which is updated on
intervals.

The problem occurs the user clicks a button to open a child form. The
child form is created. But before initialization of the child form has
finished, the DataGridView on the main form is updated. Seemingly
because of this, the main form gets focus and is moved to the front,
and the child form is moved to the back. The user can manually put
focus on the child form again and continue working, but tuhis is a
behaviour that is very anoying to the end users.

Have any of you encountered something like this before?

The non-modal strategy is by design. The users want to be able to go
back to the main form, without closing the child form. Therefore, I'm
searching primarily for any help on the focus problem, and will only
use a modal child form strategy if no resolution to the problem can be
found.

Thanks in advance,
Christer
 
M

Mike

Hi,



If you hook into the event Shown this will allow you to bring the form to
the front when it is shown for the first time.



http://msdn2.microsoft.com/en-us/library/system.windows.forms.form.shown.aspx



- Mike



---------------------------------------------------------------------------------
<a href="http://www.cogitar.net"> Cogitar Software. (
http://www.cogitar.net ) </a>
http://www.cogitar.net Cogitar Software. (Software Development and Managment
Systems)
http://www.web-dominion.co.uk Web-Dominion. (Web Design and hosting )
http://shop-dominion.com (senery landscape pictur gallery)
---------------------------------------------------------------------------------



Hi all,

An application I am woking on consist of a main form. On the main form
there are several possible ways for the user to open a non-modal child
forms to display even more information.

The problem I am encountering is about loss of focus. Let's say here,
that initialization of the child form takes about ½ second, from the
point where the window is first shown to the point where all controls
have been rendered and set with data.

Now, on the main form there is a datagridview which is updated on
intervals.

The problem occurs the user clicks a button to open a child form. The
child form is created. But before initialization of the child form has
finished, the DataGridView on the main form is updated. Seemingly
because of this, the main form gets focus and is moved to the front,
and the child form is moved to the back. The user can manually put
focus on the child form again and continue working, but tuhis is a
behaviour that is very anoying to the end users.

Have any of you encountered something like this before?

The non-modal strategy is by design. The users want to be able to go
back to the main form, without closing the child form. Therefore, I'm
searching primarily for any help on the focus problem, and will only
use a modal child form strategy if no resolution to the problem can be
found.

Thanks in advance,
Christer
 
M

Michael C

Christer said:
The non-modal strategy is by design. The users want to be able to go
back to the main form, without closing the child form. Therefore, I'm
searching primarily for any help on the focus problem, and will only
use a modal child form strategy if no resolution to the problem can be
found.

Even if you solve the problem you are creating a potentially annoying
feature for users. Some users will accidentally click the main form causing
the child form to be hidden. Other's will double click whatever shows the
child form causing the main form to jump to the front again (this could be
your problem btw). You will also create potential problems for yourself in
that programming this could suddenly become *much* more difficult. I presume
what happens in each form is dependant on each other in some way. You will
need to write code to sync the 2 forms somehow. The behaviour you're trying
to create is pretty much non-standard windows behaviour for good reason.

However, that doesn't mean that it's never appropriate. Maybe your
circumstance warrant this sort of design. If that's the case then most
likely the best option is to set the form so it floats above your main
window. I can't remember how to do that but it's not difficult. (set it as
owner or something?)

What are you trying to do exactly and why does the customer need access to
the main form still?

Michael
 
C

Christer

Even if you solve the problem you are creating a potentially annoying
feature for users. Some users will accidentally click the main form causing
the child form to be hidden. Other's will double click whatever shows the
child form causing the main form to jump to the front again (this could be
your problem btw). You will also create potential problems for yourself in
that programming this could suddenly become *much* more difficult. I presume
what happens in each form is dependant on each other in some way. You will
need to write code to sync the 2 forms somehow. The behaviour you're trying
to create is pretty much non-standard windows behaviour for good reason.

However, that doesn't mean that it's never appropriate. Maybe your
circumstance warrant this sort of design. If that's the case then most
likely the best option is to set the form so it floats above your main
window. I can't remember how to do that but it's not difficult. (set it as
owner or something?)

What are you trying to do exactly and why does the customer need access to
the main form still?

Well, it's usage pattern a bit like when using a mail program. While
writing an e-mail in a child window, you might want to return to the
main window to read a new mail, or even start one more new mail. And
they would prefer to be able to do the same in this application.

I'd really like some info on that owner strategy.

Christer
 
C

Christer

Thank you for your feedback...

In the child window i have tried

_view.Activate();
_view.BringToFront();
_view.Focus();

in the Load event...

(I'm doing MVC, hence the _view and not "this." statement).

But apparently the statements above still does not produced the
desired result. I suspect that the load is actually fired too early
with regards to the problem described above, and therefore before
rendering is actually done. I more require some DoneRendering event of
some sorts. I understand the basic idea about the event you sent in
your previous post, but do you know where in the sequence of form
evens?

Kind regards,
Christer
 
M

Michael C

Christer said:
Well, it's usage pattern a bit like when using a mail program. While
writing an e-mail in a child window, you might want to return to the
main window to read a new mail, or even start one more new mail. And
they would prefer to be able to do the same in this application.

I'd really like some info on that owner strategy.


Form2 f = new Form2();
f.Owner = this;
f.Show();

I'm not sure how you'd solve your original problem except to disable updates
while waiting for the form to show. Does it steal back the focus once the
popup form has got it?
 
C

Christer

Thanks for the feedback!

No, the main form does not steal back the focus, if an update is
performed after the child forms is rendered. It only happens when the
main form updates during rendering of the child form (or so it
seems).

I did not know setting the Owner property would have any effect except
in MDI applications. What would the effect of the statements below be
in a non-MDI solution?

Christer
 
M

Michael C

Christer said:
Thanks for the feedback!

No, the main form does not steal back the focus, if an update is
performed after the child forms is rendered. It only happens when the
main form updates during rendering of the child form (or so it
seems).

Did stopping the refresh during this time solve the problem then?
I did not know setting the Owner property would have any effect except
in MDI applications. What would the effect of the statements below be
in a non-MDI solution?

It keeps the popup form always on top of its owners window. If also causes
the popup form to be closed when its owner is closed. It does not keep it on
top of other applications. This could be quite effective in your situation.
On the other hand users might find it annoying.

Michael
 

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