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

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
Back
Top