Setting focus doesn't work

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

Hi,

I have a bunch of forms in a DLL that I call from my main application. The
one form is a login form, and I have the tab order set in the order I want
it (password box first, then ok button then cancel button then database
selection combo box then user name text box, then back to password text box)
now the password, user name and database entry's are in a group box frame.
the buttons (Ok and Cancel) are outside the group frame.

Now that the tab order is set, I want to set focus by default to the
password text box. The user name is entered automaticly by the system as per
the current user logged into active directory on the system. (of course the
user can change who logs in by changeing the text box). When I do this in
the load event

txtPassword.PasswordChar = bdbGeneral.PASSWORDCHAR ' make the better looking
mask character (chrW is unicode characters)

' set live as the default

Me.cboDatabase.value = settings.ReadSetting("initialDatabase")

Me.txtPassword.Text = "password"

Me.txtUser.Text =
System.Security.Principal.WindowsIdentity.GetCurrent.Name().Substring(System
..Security.Principal.WindowsIdentity.GetCurrent.Name.IndexOf("\") + 1)

Me.txtPassword.Focus()



now, when I run the form, txtpassword does not have focus. The focus is
starting on the cancel button. I do have the cancel button as the form
default cancel button and the ok button as the forms default acept button.
What is causeing this and how would i fix it? I thought using the focus
method was going to give teh textbox gocus.... it has in the past.. thanks
 
Brian Henry said:
Me.txtPassword.Focus()



now, when I run the form, txtpassword does not have focus. The focus
is starting on the cancel button. I do have the cancel button as the
form default cancel button and the ok button as the forms default
acept button. What is causeing this and how would i fix it? I thought
using the focus method was going to give teh textbox gocus.... it has
in the past.. thanks

Did you also set the tabindex of the groupbox? Must be smaller than the
one's of the buttons.

An important precondition to be able to set the focus (see docs on Focus
method) is not met: the form is not visible within form_load.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
how would you go about setting the default focus then if you can not set it
on load (i ask this because this is how we do it in foxpro and a few other
languages ive worked with)? thanks
 
Back
Top