By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Setting focus

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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]
Nov 21 '05 #2

P: n/a
Tom Shelton wrote:
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,

Thanks,

Had tried it in the activated event to no avail but your second
suggestion worked thanks

Jack
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.