TextBox.Focus() problem

  • Thread starter Christian Schwarz
  • Start date
C

Christian Schwarz

Hello,

I've a form containing two Labels, two TextBoxes and a button. The form is
created only once. Every time it's needed it's showed using ShowDialog() and
afterwards closed using Close() method. Before showing the form the focus is
set on one of the two TextBoxes. When showing the form for the very first
time, Focus() method works well. But the next time the TextBox doesn't get
the focus. Although Focus() returns true, the Focused property returns false
....

First, I thaught that setting the focus on the control *before* the form is
actually shown is the problem. But even using the form's Load event to set
the focus doesn't work.

Does anybody have an idea by what this problem is caused ?

Greetings, Christian
 
T

Tom Krueger [MSFT]

Hello Christian,

Hmm, setting the focus to the control in the form load should do it for
you.
I tested it to be sure. I put two textboxes on a form and called the
following from Form_Load.
textBox2.Focus();

Could you create a test application and just try to reproduce this problem.
If you are still having trouble post the code so we can figure it out.

Take care,

Tom


--
Tom Krueger
Microsoft Corporation
Program Manager
http://weblogs.asp.net/tom_krueger

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 

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

Windows XP textbox.Focus() 0
get rid of focus 3
Focus on textbox 1
How to scroll to text box when keyboard is displayed 6
Form.KeyPreview in CF 4
Validating a Textbox 3
OpenNetCF sendkey to OpenNetCF webbrowser 0
CF Mouse wheel events 1

Top