Form_Load (how to focus a control ?)

  • Thread starter Thread starter Cybertof
  • Start date Start date
C

Cybertof

Hello,

I would like to focus on a special control on my form during Form_Load
inialisation. The focused control may change according to internal
parameter value (so it's not always the same control).

How to do it ?

Example :
tbName.Focus();

My problem is that within the FormLoad, setting focus on a control does
not seem to have effect.


Regards,
Cybertof.
 
The control with the smallest (by this I mean a is smaller than b if a < b)
TabIndex is focused on startup automatically. Change this property of the
control you want to have the initial focus.

Hope that helps,
-JG
 
I use a timer object to set the focus after the Form loads.

Drop a Timer control on the form set it to Enable = true, Interval = 1. Then
register the Tick event.

In the handler for that event set the focus to the desired control. That
allows you to keep your tab order in tact.

HTH;
Eric Cadwell
http://www.origincontrols.com
 
If you use groupboxes, you may need to set focus to the groupbox before
setting focus to a control within it. Same with panels, or any controls
that can contain other controls.
 
Thanks all.

I have found another method : setting the focus in the activate event,
so i'm sure all the controls are visible when focusing on them.

Unfortunately, i have to deal with a status boolean flag saying so my
focusing operates only the first time it activates (after the load).

The TabIndex is good if the control to have focus does not change
according to custom settings.
In my cas, i had to do it programmaticaly.
Bad luck that it cannot be done in the form_load event.


Regards,
Cybertof.
 
Back
Top