Board index » delphi » !!!! Enter Key -> Tab Key

!!!! Enter Key -> Tab Key

Please Help!!

How can I use Enter Key to move from one component to another in a Form?

Any help appreciated.

--
/////////////////////////////////////////////////////////////
   0   0       regards
      ||         rj...@mbox3.singnet.com.sg
     ==        jonathan yeo
    hello                                                          
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

 

Re:!!!! Enter Key -> Tab Key


Quote
>   "Jonathan Yeo H.M." <rj...@mbox3.singnet.com.sg> writes:
>  How can I use Enter Key to move from one component to another in a Form?

Set form key preview to true and add a form keydown event:

  if (key = 13)  then
    begin
      key := 0;
      selectnext(activecontrol,getkeystate(vk_shift) and $80 = 0,True);
    end;

johan

Re:!!!! Enter Key -> Tab Key


Jonathan -

Quote
>How can I use Enter Key to move from one component to another in a Form?

Despite Johan's advise, I would advise that you NOT DO THIS!  Your users are now
in a windowing environment, and the standard is that focus moves from control to
control with the TAB key, not the ENTER key.  This is a major change for _lots_
of people who are used to DOS based systems.  However, they will need to make
the change eventually, and if you program your system to use the ENTER key, then
your system won't work like everything else in Windows does.

--
Clayton Neff
Software Project Leader
The Personal Marketing Company, Inc.
11843 West 83rd Terrace
Lenexa, KS  66214
(913)492-0322
clay...@tpmco.com

Re:!!!! Enter Key -> Tab Key


Quote
>   cn...@primenet.com (Clayton Neff) writes:
>  >How can I use Enter Key to move from one component to another in a Form?
>  Despite Johan's advise, I would advise that you NOT DO THIS!  Your users are now
>  in a windowing environment, and the standard is that focus moves from control to
>  control with the TAB key, not the ENTER key.  This is a major change for _lots_
>  of people who are used to DOS based systems.  However, they will need to make
>  the change eventually, and if you program your system to use the ENTER key, then
>  your system won't work like everything else in Windows does.

Well, I agree to that principle but this was a technical answer and I am sure that there are instances where you are doing a program for specific purposes that warrants
the use of non-standard Windows behaviour.

johan

Re:!!!! Enter Key -> Tab Key


An easy way to do this for a particular form(s) is to put this code in your
OnKeyPress event for the form, also make sure the KeyPreview for the form
is set to true.

procedure Tfm_NewTrans.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if (key = #13) then
    begin
      perform(WM_NEXTDLGCTL, 0, 0);
      key := #0
    end
end;

Keep in mind that this will effectively bypass the enter key activating a
button that you may want activated when the button has focus and the user
presses the enter key.  You can fix this by adding code to check which
control has focus before turning the above code loose. An example would be:

procedure Tfm_MyForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
   if  (not ActiveControl = ButtonCancel) and (not ActiveControl =
ButtonSave) then
     if (key = #13) then
       begin
          perform(WM_NEXTDLGCTL, 0, 0);
          key := #0
       end
end;

Ivanov Alex <iva...@te.net.ua> wrote in article
<01bd1f30$13927ae0$ba508ac3@My>...

Quote

> Jonathan Yeo H.M. <rj...@mbox3.singnet.com.sg> wrote in article
> <01bd1c12$997f7ca0$61b315a5@p166>...
> > Please Help!!

> > How can I use Enter Key to move from one component to another in a
Form?

> > Any help appreciated.

> > --
> > /////////////////////////////////////////////////////////////
> >    0   0       regards
> >       ||         rj...@mbox3.singnet.com.sg
> >      ==        jonathan yeo
> >     hello                                                          
> > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

> Set form key preview to true and see attachment.

Re:!!!! Enter Key -> Tab Key


Quote
cn...@primenet.com (Clayton Neff) wrote:
>>How can I use Enter Key to move from one component to another in a Form?
>Despite Johan's advise, I would advise that you NOT DO THIS!  Your users are now
>in a windowing environment, and the standard is that focus moves from control to
>control with the TAB key, not the ENTER key.

Despite Microsoft's insistence that this is the way things work,
observation will indicate that, in practice, this only holds true for
dialog boxes.  Persistent forms generally use tab and enter
interchangeably.

Quote
>  This is a major change for _lots_
>of people who are used to DOS based systems.  However, they will need to make
>the change eventually, and if you program your system to use the ENTER key, then
>your system won't work like everything else in Windows does.

Only if programmers like you and me succumb to the will of Microsoft.
And I refuse to do so.  It's a bad standard.  Most (US) keyboards make
Enter more convenient for frequent use using both size and placement.
Therefore, it should be assigned to the (common) task of moving to the
next field instead of the (much less common) task of finishing with a
form.  The only rationale I can find for why MS would advocate this
usage is a desire to conform to the way things were done on dumb
terminals attached to mainframes, where 'Enter' meant 'send data to
the computer'.  That usage is obsolete and, given the layout of modern
keyboards, inconvenient.

And, of course, MS will _never_ change their standards.  I mean, they
would never do something like change the Win3/Win95 'click icon to
select, double-click to execute' standard to 'put cursor over icon to
select, click to execute', right?  Oh, yeah - they already changed
that in IE4 and Win98...

--
To a man who only has Visual Basic, everything looks like a control array.

Other Threads