TextBox.Focus() doesn't focus

K

kwarnke

I have a textobx that appears on a tab page. I'm trying to set the focus on
that textbox but it doesn't seem to work. The focus always defaults to a
button that is on the form (but not on the tab page).

Any ideas? I tried focusing on the tab page and then on the text box to no
avail.

Thanks,
- Kevin
 
H

Herfried K. Wagner [MVP]

* "kwarnke said:
I have a textobx that appears on a tab page. I'm trying to set the focus on
that textbox but it doesn't seem to work. The focus always defaults to a
button that is on the form (but not on the tab page).

Are you sure the form and the controls are visible when calling the
textbox's 'Focus' method?
 
A

Andrew Bingham

Try instrumenting the code with the control's "CanFocus" property to see
whether it CAN get the focus ?

--
****************************************************************************
andrewbingham.com

tel 01223 514674 (Cambridge)
mobile 07970 161057
fax 07970 601283
email (e-mail address removed)

DISCLAIMER, PLEASE NOTE:
This communication is for the attention of the named recipient only
The content should not be passed on to any other person.
It is sent in good faith, in confidence, and without legal responsibility.

VIRUS CHECK
Emails and attachments are virus checked using Norton® AntiVirus®
2002 which is regularly updated. However it remains the recipients
responsibility to check emails and attachments sent, or forwarded,
from andrewbingham.com for viruses and macro viruses
****************************************************************************
 
J

Justin Rogers

Focus returns true/false success. Note that synchronous ordering when working
with controls can sometimes cause your values to get reset. If you are calling
the Focus method from within an event handler, try using:

private delegate bool BooleanMethodInvoker();
public void Some_EventHandler(...) {
myTextBox.BeginInvoke(new BooleanMethodInvoker(myTextBox.Focus));
}

An examination of using the invoke methods can be found here:
http://weblogs.asp.net/justin_rogers/articles/126345.aspx
 

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

Similar Threads


Top