Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread Focus
Mon, Oct 19 2015 6:48 AMPermanent Link

Matthew Jones

I have a login form, with name and password. The edits have their
OnKeyDown events set to look for Enter, and that works fine. What
doesn't work is the initial focus for the whole page. I refresh, and
nothing at all has focus. I can't tab to anywhere. I tried putting
editEMail.SetFocus in the OnShow, but that doesn't make any difference.

Anyone know how to set the initial focus to an edit box?

--

Matthew Jones


function TfrmAdminLogin.editEmailKeyDown(Sender: TObject; Key: Integer;
ShiftKey, CtrlKey, AltKey: Boolean): Boolean;
begin
   if Key = 13 then
       btnLoginClick(nil);
   Result := true;
end;
Mon, Oct 19 2015 11:00 AMPermanent Link

Frederick Chin

"Matthew Jones" wrote:

/*
I have a login form, with name and password. The edits have their
OnKeyDown events set to look for Enter, and that works fine. What
doesn't work is the initial focus for the whole page. I refresh, and
nothing at all has focus. I can't tab to anywhere. I tried putting
editEMail.SetFocus in the OnShow, but that doesn't make any difference.

Anyone know how to set the initial focus to an edit box?
*/

The TEdit.Setfocus should work but I think your code for the OnKeyDown should be:-

function TfrmAdminLogin.editEmailKeyDown(Sender: TObject; Key: Integer;
ShiftKey, CtrlKey, AltKey: Boolean): Boolean;
begin
   Result:=True;
   if Key = 13 then begin
       btnLoginClick(nil);
       Result := False;
  end;
end;

Frederick
Mon, Oct 19 2015 11:24 AMPermanent Link

Matthew Jones

Frederick Chin wrote:

> The TEdit.Setfocus should work

Hmm, it isn't doing though... Not in Chrome anyway.


> but I think your code for the
> OnKeyDown should be:-
>
> function TfrmAdminLogin.editEmailKeyDown(Sender: TObject; Key:
> Integer; ShiftKey, CtrlKey, AltKey: Boolean): Boolean;
> begin
>     Result:=True;
>     if Key = 13 then begin
>         btnLoginClick(nil);
>         Result := False;
>    end;
> end;

I think you are right if I cared about the key not being processed, but
since it is inert it won't matter.

--

Matthew Jones
Mon, Oct 19 2015 11:36 AMPermanent Link

Frederick Chin

"Matthew Jones" wrote:

/*
Hmm, it isn't doing though... Not in Chrome anyway.
*/

I use Chrome too and it definitely works. Maybe you could create a new project and see if the Setfocus works there.

Frederick
Mon, Oct 19 2015 11:44 AMPermanent Link

Raul

Globestar Systems

Team Elevate Team Elevate

On 10/19/2015 6:48 AM, Matthew Jones wrote:
> I have a login form, with name and password. The edits have their
> OnKeyDown events set to look for Enter, and that works fine. What
> doesn't work is the initial focus for the whole page. I refresh, and
> nothing at all has focus. I can't tab to anywhere. I tried putting
> editEMail.SetFocus in the OnShow, but that doesn't make any difference.
>
> Anyone know how to set the initial focus to an edit box?

It works fine here as described - TDialog based form with first 2
TLabels, tedit, TPasswordEdit and TButton.

TEdit has taborder 0 and always gets focus and everything works as
expected - - even after refresh.

You need to provide more info - what is your form based on (TForm,
TDialog). Do you have the controls wrapped in any containers, are you
running any other code in form init or onshow , etc ?

Raul



Mon, Oct 19 2015 11:46 AMPermanent Link

Raul

Globestar Systems

Team Elevate Team Elevate

On 10/19/2015 11:44 AM, Raul wrote:
> It works fine here as described - TDialog based form with first 2
> TLabels, tedit, TPasswordEdit and TButton.
> TEdit has taborder 0 and always gets focus and everything works as
> expected - - even after refresh.

Forgot to mention i do not need call to setfocus - tEdit automatically
gets it as 1st focusable control anyways.

Raul
Tue, Oct 20 2015 3:49 AMPermanent Link

Matthew Jones

Raul wrote:

> You need to provide more info - what is your form based on (TForm,
> TDialog). Do you have the controls wrapped in any containers, are you
> running any other code in form init or onshow , etc ?

I have a main form, and on that is a form (parented). On that form (the
login form) is a TPanel, and on that is the edit. As I say, I do an F5
refresh, and then Tab does *nothing* at all. I would expect it to go
around the page or UI or something, but it appears stuck.

However, since it works for others, I will persist with experiments and
see what is up.

--

Matthew Jones
Image