VFP Blinky Cursor

Hi all. Have a simple login form, just email and password textboxes. The email box has TabStop T and a Tab Index of 1.

When the form loads I would like to have the cursor placed inside the email textbox so the user can just start typing, instead of having to click in the box first.

I have tried to do this using code in init:
thisform.txtEmail.setfocus()
thisform.txtEmail.click()

and have also tried using the same code in the email textboxes' WHEN and GotFocus.

Additionally I've tried each of these with SelectOnEntry T and F.
Nothing has worked. I'm sure this has to be simple. Help please.
formadmirerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
Maybe the form is not active. Make it active first and then look at the fields.
0
pcelbaCommented:
I would also try:
AlwaysOnTop = .T.

and following commands in the form.Refresh:

ACTIVATE WINDOW <YourLoginFormName>
THISFORM.<YourTextBox>.SetFocus

(suppose the form is displayed by DO FORM command)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
You need the SetFocus not the Click. Is that code in the Form's Init Event?
0
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

formadmirerAuthor Commented:
I've tried with just setfocus in ever conceivable location but to no avail. Added the click since when the form is displayed, if I click anywhere on the form itself the cursor immediately pops up inside the email textbox like I want. It just won't do it without a click first.

The form is so simple. Literally it's just an email and password box with nothing in the init except for the two lines of code above.

I figured I'd use this simple form to find a fix as all the forms within my app have the same problem. No matter what I do I can't get a cursor to appear in the first textbox after the form loads.

And it's not just that the cursor isn't visible - it isn't there. If you load the form and begin to type the keystrokes act upon Window's desktop, and not the form or it's contents.

----
Maybe the form is not active? - it is called from within Main, loads before most anything else and is the only form activated in Main.

Is the code in the Form's Init? - yes. I've tried the Form's init, the textboxe's Init, When and GotFocus. Nothing I've tried has resulted in the cursor appearing in the textbox ready to take input.
0
pcelbaCommented:
So and what about my questions?

Is the form called by DO FORM ?

If yes, did you try
ACTIVATE WINDOW <YourLoginFormName>
THISFORM.<YourTextBox>.SetFocus

in the Form.Refresh ?
0
pcelbaCommented:
And all of above attempts are unnecessary if you make to form MODAL.

If you would ask why? Then the answer is simple: The Main code continues after the DO FORM <NonModalForm> command until it finds the READ EVENTS and some instruction may cause the login window deactivation.
0
formadmirerAuthor Commented:
Thanks. I'll give the MODAL option a shot.

I did find a workable solution on another forum after lots of searching both last night and this morning. For anyone else with the same issue the solution is here:

http://www.tek-tips.com/viewthread.cfm?qid=583761

I'll post back about my experience with setting the form to MODAL shortly.
0
formadmirerAuthor Commented:
Sorry pcelba for overlooking a response to your suggestions. Yes, I did try what you suggested and set the form to Always ON Top and placed  

ACTIVATE WINDOW <YourLoginFormName>
THISFORM.<YourTextBox>.SetFocus

into the form's refresh method without success. I also tried it in the init, with the form as both Modal and Modeless but to no avail.

Additionally I've now tried the suggestion to make the form Modal instead of Modeless, and that too did not work.

Other suggestions I've read for the issue said to remove _screen.visible=.F. in the program's MAIN and instead use a config.fpw with SCREEN=OFF. That did not work.

A few other suggestions revolved around first removing the form's focus and then reestablishing it. Those did not work either.

But I did find one thing that does work at the link posted above, so for me the issue is resolved and I'll mark this as so.

I appreciate all the help and suggestions - thanks!
0
pcelbaCommented:
Great it works for you but we still don't know where the problem is... If you have conditions specific to ones described in Tek-tips web (VFP 6 and SCREEN OFF) then all our hints were out of scope probably...

OK, no time and no reason to investigate it further.

Thank you for knowledge sharing!
0
Olaf DoschkeSoftware DeveloperCommented:
If you used the starred solution
Declare BringWindowToTop in User32 Long nhWnd

You better change to SetForegroundWindow:

DECLARE INTEGER SetForegroundWindow IN user32;
      INTEGER hwnd

The hwnd does not need to be determined by FindWindow, hwnd is a form property of _screen and any vfp form, so if you do DO FORM, you do

DO FORM login.scx NAME loLogin
SetForegroundWindow(loLogin.hwnd)

From this discussion you can see foreground window will be made the global foreground window, the active window of all currently running applications.

I used it when I wanted to let an InternetExplorer.Application window with HTML formatted application news be in front of everything, after the login. It's unfortunate, but sometimes even new windows of the recently started application do not automatically become foreground windows.

Bye, Olaf.

Also: Calling a control.click does not cause the same as clicking. It's the mouse click windows event, that is forwarded to VFP, which then calls the click method, besides many other things, but calling click does not cause all the events including activating the form and making it the foreground window, if it isn't already.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
FoxPro

From novice to tech pro — start learning today.