TextBox.Focus() problem

  • Thread starter Thread starter Christian Schwarz
  • Start date 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
 
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
 
Back
Top