On 2005-06-08, Jack Russell <ja***@norubbish.tpg.com.au> wrote:
I have a form containing a tab control
I want focus set to a particular text box when the form opens.
However doing this in the load form event
If TabControl1.SelectedIndex = 0 Then
If txtFileName.CanFocus Then
txtFileName.Focus()
End If
End If
I get false from canfocus.
I can do it fine in the tabcontrol.selectedindexchanged event so why
can't I do it in load?
Thanks
Controls have not necessarily completed their initilization in the
form's load event. A control to receive the focus, must be enabled,
visible, and have a handle. You may want to move this code to the forms
activated event - though, you will want to put a flag to make sure this
only happens the first time the activated event fires.
You might also make this happen if you do something like:
Me.Visible = True
Me.Refresh
If txtFileName.CanFocus Then
txtFileName.Focus ()
End If
In your load event. This will force the form to become visible and
redraw it self....
--
Tom Shelton [MVP]