Cannot set focus to an object in the form load event?

G

Guest

Hello:

I have a windows form that has a command button. I was trying to set focus
on it in the form's Load event. It did not work. However, moving the line of
code to the form's activate event, it does.

Any reason? Are there any other nuances about when to use the FormLoad and
FormActivate events, like when and more importantly when not to use these
events?

Venkat
 
H

Herfried K. Wagner [MVP]

vvenk said:
I have a windows form that has a command button. I was
trying to set focus on it in the form's Load event. It did
not work. However, moving the line of code to the form's
activate event, it does.

Any reason?

The focus can only be set to a control that is (1) visible and (2) enabled.
In the form's 'Load' event, the form is not yet visible and thus setting the
focus doesn't take effect.
 

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